60 likes | 196 Views
Timer & Format. Microsoft.VisualBasic.Timer. Public Class Form1 Dim start_time As Double Dim t1 As Single = 10 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Start()
E N D
Microsoft.VisualBasic.Timer Public Class Form1 Dim start_time As Double Dim t1 As Single = 10 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Start() start_time = Microsoft.VisualBasic.Timer Label2.Text = start_time ‘ Label2.Text = Format(start_time, "#.00") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim t As Double Timer1.Stop() t = Microsoft.VisualBasic.Timer - start_time Label2.Text = t ‘Label2.Text = Format(t, "#.00") End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick t1 = t1 - Timer1.Interval / 1000 Label1.Text = t1 End Sub End Class
內建函數Format • Format( )函數 • 格式化字元說明: 接續下頁
內建函數Format • Format( )函數 • 格式字元說明:
時間延遲 Sub delay(ByVal Timelast) 'Dim TimeLast As Integer = 100 ' 要延遲 t 秒,就設為 Timelast *1000 Dim Start As Integer = Environment.TickCount() Do If Environment.TickCount() - Start > TimeLast Then Exit Do Application.DoEvents() ‘要記得寫這行,不然都在跑迴圈,畫面可能會不見 Loop End Sub Private Sub Button1_Click(ByVal sender As…….) Handles Button1.Click delay(2000) End Sub
內建函數Format • Format( )函數 • 用來設定數值資料及時間日期資料的格式 • 語法: Format(資料, "格式化字元") 例: Format(資料, “#.00")