1 / 6

Timer & Format

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()

freira
Download Presentation

Timer & Format

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

  3. 內建函數Format • Format( )函數 • 格式化字元說明: 接續下頁

  4. 內建函數Format • Format( )函數 • 格式字元說明:

  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) End Sub

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

More Related