VB 延时执行 有没有省资源的呀 !

来源:百度知道 编辑:UC知道 时间:2024/06/18 08:30:16
Private Sub waittime(delay As Single)
Dim starttime As Single
starttime = Timer
Do Until (Timer - starttime) > delay
DoEvents
Loop
End Sub
以上延时消耗的资源太大 !那位高人指点一个不占用资源的延时代码呀 !
可以给个实例吗?最好精确到毫秒的!谢谢

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
For i = 1 To 1000
Label1 = "" & i & "追加字符" & Chr(13) & Chr(10) & Label1 & ""
Sleep (100)
Next
End Sub

Private Sub Form_Load()
Label1 = "字符串"
End Sub
执行!程序假死无响应

我才学VB一天 !嘎嘎!各位高人多多指教

可以用sleep这个api,声明如下:
Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

使用方法:
doevents
sleep 时间(单位:毫秒)

注意:sleep前一句一定要加上doevents,否则假死

1.以上消耗资源并不大
2.延时可以用delay这个API
3.如果要可以延时中响应操作(不卡死)可以用Timer