Presentation is loading. Please wait.

Presentation is loading. Please wait.

Timer & Format.

Similar presentations


Presentation on theme: "Timer & Format."— Presentation transcript:

1 Timer & Format

2 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") 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 Class

3 內建函數Format Format( )函數 格式化字元說明: 格式化字元 說明 數值資料 井字號(#) 代表預留位數(數字不存在就不顯示)
零格式字元 (0) 代表預留位數(數字不存在就顯示0) 英文句號(.) 代表小數點 時間日期資料 冒號(:) 代表時間分隔符號,用來分隔小時、分鐘、及秒數 斜線(/) 代表日期分隔符號,用來分隔年份、月份、及日期 接續下頁

4 內建函數Format Format( )函數 格式字元說明: 格式化字元 說明 時間日期資料 秒數格式字元(s) 代表秒數
代表分鐘 小時格式字元(h、H) "h" 代表以12小時制來顯示小時;"H" 代表以24小時制來顯示小時 日期格式字元(d) 代表日期 月份格式字元(M) 代表月份 年份格式字元(y) 代表年份

5 時間延遲 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)

6 內建函數Format Format( )函數 用來設定數值資料及時間日期資料的格式 語法: Format(資料, "格式化字元")
例: Format(資料, “#.00")


Download ppt "Timer & Format."

Similar presentations


Ads by Google