读书人

vb中怎么延迟时间

发布时间: 2012-01-21 21:31:43 作者: rapoo

vb中如何延迟时间
vb中如何延迟时间,程序运行到一段代码,停顿5秒,然后继续往下运行

[解决办法]
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
DoEvents
Sleep 5000



[解决办法]
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim StartTm&

Private Sub Command1_Click()
Call DataSend(&H67, MSComm1)
Call DelayCycle(1000)
Call DataSend(&H6A, MSComm1)
Call DelayCycle(1000)
End Sub

Public Sub DelayCycle(Optional Dtm As Long)
On Error Resume Next
StartTm = GetTickCount
Do
DoEvents
Loop Until GetTickCount >= StartTm + Dtm
End Sub

[解决办法]

VB code
   Dim NowTime As Date   Dim IsExit As Boolean   MsgBox "开始等待5秒"   NowTime = Now   IsExit = False   Do      DoEvents      If DateDiff("s", NowTime, Now) >= 5 Then IsExit = True   Loop While IsExit = False   MsgBox "已等待5秒"
[解决办法]
VB code
Private Sub Command1_Click()   MsgBox "开始等待5秒"   Call StopTime(5)   MsgBox "已等待5秒"End SubPrivate Sub StopTime(S As Long)   Dim NowTime As Date   NowTime = Now   Do      DoEvents   Loop While DateDiff("s", NowTime, Now) < SEnd Sub 

读书人网 >VB

热点推荐