Fungsi sleep menggunakan Sleep Kernel32.dll:
- Mem-freeze GUI (membekukan tampilan)
- Hitungan dalam millisecond
- Tidak mem-freeze GUI
- Hitungan dalam second
Private Sub Sleep(ByVal HowLong As Date) Dim endDate As Date endDate = DateAdd("s", HowLong, Now) While endDate > Now DoEvents Wend End SubJika Anda mau bereksperimen maka buatlah kodenya seperti di bawah ini kemudian bandingkan antara fungsi sleep Kernel32.dll dengan fungsi sleep tanpa API.
Option Explicit 'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Command1_Click() Label1.Caption = "Mulai menjalankan fungsi sleep atau wait" Label1.Refresh Sleep 5 'sleep/wait/hentikan eksekusi kode ke baris berikutnya selama 5 detik Label1.Caption = "Terhenti selama 5 detik" End Sub Private Sub Command2_Click() Dim frm As New Form1 frm.Show End Sub Private Sub Timer1_Timer() Static i As Integer Caption = i i = i + 1 End Sub Private Sub Sleep(ByVal HowLong As Date) Dim endDate As Date endDate = DateAdd("s", HowLong, Now) While endDate > Now DoEvents Wend End SubDemikianlah seputar fungsi sleep atau wait, menggunakan API dan tanpa menggunakan API.
Option Explicit Private Function Sleep(mSecs As Long) As Double Dim Duration! Duration! = Timer + mSecs Do Until Timer > Duration! DoEvents Loop End Function Private Sub Command1_Click() Sleep 0.9 MsgBox "Test" End Sub
0 komentar:
Posting Komentar