⑴ VB的延时问题
Public Function Delay(DelaySeconds As Single, Optional DoEventsEnbled As Boolean = True, Optional ShowErrorMsg As Boolean = True) As Long
'=====延时,秒数=====
'独立函数
'
'DelaySeconds 秒数,可以为小数
'DoEventsEnble 延时过程中是否执行 Doevnts
'正常处理返回1,错误返回-1
Static Abort As Boolean
If Abort Then Exit Function
On Error GoTo er
If DelaySeconds >= 172800 Then
MsgBox "函数中的DelaySeconds值为:" & CStr(DelaySeconds) & "超过了最大限度(172800)。", vbCritical
Exit Function '延时超过了最大限度
End If
Dim St As Single, Et As Single
St = Timer '当前的时间
If DoEventsEnbled = True Then '
Do
Et = Timer
If Et < St Then '越过了午夜0时
St = 86400 - St
End If
DoEvents
Loop Until Et - St >= DelaySeconds
Else
Do
Et = Timer
If Et < St Then '越过了午夜0时
St = 86400 - St
End If
Loop Until Et - St >= DelaySeconds
End If
Delay = 1
Exit Function
er:
If ShowErrorMsg = True Then
If MsgBox("在执行Delay函数时发生了未知的错误," & vbCrLf _
& "输入参数 DelaySeconds=" & CStr(DelaySeconds) & ", DoEventsEnbled=" & CStr(DoEventsEnbled) & vbCrLf _
& "系统返回的错误信息:(" & CStr(Err.Number) & ")" & Err.Description & vbCrLf & vbCrLf & "是否要一直忽略这个函数的执行?", vbYesNo + vbDefaultButton2 + vbCritical, "错误") = vbYes Then
Abort = True
End If
End If
Delay = -1
End Function
⑵ vb延时方法
延时最好的方法是锻炼身体,饮食营养健康加上好的心态,增加情趣以及延长时间都能够起到帮助的。
炒肉类菜肴,要求炒得鲜嫩可口。炒菜的火候,投料的顺序都有讲究。以炒猪肉片为例说明:猪肉洗净切片,炒锅上火烧热,加入底油,油热后,先将葱花与肉片一同下锅煸炒,见肉表面发白接近半熟时,先烹入少许醋拌炒,待醋味迅速蒸发,再加入姜汁搅拌入味。然后加酱油、少许水,水沸后,放入副料,最后勾交,淋少许明油出勺。炒蔬菜类菜肴,则可用热锅温油,先下鲜姜末,炸出香味后,再下切好的蔬菜,迅速翻炒,待蔬菜响声已过,质地变软时,再加酱油炒匀,再放入少许汤水、食盐、白糖、味精,炒匀后,勾芡并淋香油即可出勺。
f
⑶ 怎样实现vb程序条件满足时,加个延迟后,进入下个条件判断
'这是网上大虾的延时delay程序,我做抽签机DIY来的,呵呵~~
---------------------------------------------------
Private Sub Com3()
changeTop
Command4(1).Caption = "抽取下一个"
Command4(2).Caption = "重新开始"
tLeft = tLeft + 1
Command4(1).Enabled = False
Dim IsOk As Boolean
Do
Label4(nLeft).Caption = ""
Label4(nLeft).Caption = DisNum()
IsOk = True
For i = 0 To (nLeft - 1)
If Label4(i).Caption = Label4(nLeft).Caption Then
IsOk = False
Label4(nLeft).ForeColor = &H990000
Delay (15) '防当机,15ms
Exit For
End If
Next i
DoEvents
Loop Until IsOk
Label4(nLeft).ForeColor = &H0
nLeft = tLeft
Delay (200) '防连击延迟
Command4(1).Enabled = True
Command4(1).SetFocus
If nLeft >= 5 Then
Command4(1).Enabled = False
Timer1.Enabled = False
Command4(2).SetFocus
Exit Sub
End If
End Sub
'-----------------------------------------------
Function Delay(ByVal DT As Long) As Boolean
'延时 DT m秒
'当 DT=0,返回Delay状态: True:未完成, False:已完成
Dim t1 As Long, t2 As Long
Static InDelay As Boolean
'
If InDelay Or DT <= 0 Then
Delay = InDelay
Exit Function
End If
'
InDelay = True
t1 = Int(Timer * 1000)
Do Until Abs(Timer * 1000 - t1) > DT '跨越0.00秒,加abs
t2 = Int(Timer * 1000)
Do: DoEvents: Loop Until Int(Timer * 1000) <> t2
DoEvents
Loop
InDelay = False
Delay = False
End Function
⑷ 如何用VB延时执行命令
Dim i As String
Private Sub Command1_Click()
Print "运行文件1"
Shell "文件路径\file1.exe"
Timer1.Interval = 20000
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
i = 0
End Sub
Private Sub Timer1_Timer()
i = i + 1
Select Case i
Case 1
Print "运行文件2"
Shell "文件路径\file2.exe"
Timer1.Interval = 10000
Case 2
Print "运行文件3"
Shell "文件路径\file3.exe"
Timer1.Interval = 5000
Case 3
Print "结束文件2并删除"
Shell "cmd /c taskkill /f /im file2.exe"
Kill "文件路径\file2.exe"
Timer1.Interval = 10000
Case 4
Print "结束文件1并删除"
Shell "cmd /c taskkill /f /im file1.exe"
Kill "文件路径\file1.exe"
Timer1.Interval = 0
Timer1.Enabled = False
End Select
End Sub
⑸ VB的延时1秒命令怎么写,在线给分
VB提倡的是用定时器控件(Timer)的方法。首先在窗体放入一个Timer1和Command1,然后输入以下代码:
PrivateSubCommand1_Click()
Timer1.Interval=1000
Timer1.Enabled=True
EndSub
PrivateSubForm_Load()
Timer1.Enabled=False
EndSub
PrivateSubTimer1_Timer()
MsgBox"这个对话框是点击按钮1秒钟后弹出来的"
Timer1.Enabled=False
EndSub
此外还可以用API函数Sleep来延时,或者利用循环结合时间函数来延时,但它们都容易造成系统阻塞,所以不建议使用。
使用定时器控件还有一个最大好处,就是在延时期间你的程序还可以继续运行处理其他事务(比如鼠标点击、键盘输入等)。而其他方法产生的延时效果,在延时期间就只能傻等,什么也做不了,甚至还有可能影响到其他程序。
⑹ 怎么在vb 中加入延时命令
PrivateSubCommand1_Click()
Me.Timer1.Interval=30*1000'定时30秒
Me.Timer1.Enabled=True
Do
IfNotTimer1.EnabledThenMsgBox"时间到!":ExitSub
DoEvents
Loop
EndSub
PrivateSubForm_Load()
Timer1.Enabled=False
EndSub
PrivateSubTimer1_Timer()
Me.Timer1.Enabled=False
EndSub
⑺ VB6.0中如何设置延时
方法很多个。
可以使用API函数Sleep
Private Declare Sub Sleep Lib "kernel32.DLL" (ByVal dwMilliseconds As Long)
调用比如睡眠1秒:Sleep(1000)
另外还有一种延时方法,即获取当前系统时间+延时时间=等待结束时间,等到了等待结束时间到了就往下执行。
Private Declare Function GetTickCount Lib "kernel32" () As Long
'自编应用函数
Private Sub WaitForMS(MillSeconds As Long)
Dim S as Long
S=GetTickCount+MillSeconds
Do
If GetTickCount=S Then Exit Sub
Loop
End Sub
这个函数的调用跟上面的相似,单位是ms。
⑻ VB 中如何使用延时函数
使用Timer控件,修改其Interval属性为1000.我的代码:Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Timer1_Timer()
Sleep 1000
Timer1.Interval = 0
End Sub
⑼ VB中如何延时执行命令!
1可以利用api sleep函数,冻结线程,但由于消息函数阻塞会导致卡屏,2可以向楼上那样创建wscript.shell对象,3使用timer控件延迟,4使用循环结构取当前时间做差判断,填充doevents语句防止占用过多cpu时间片。不懂继续问。
⑽ vb中如何实现延时功能
可以用定时器,设置个中断时间间隔,时间一到就进入中断,可用于按一定规律延时的情况。
也可以用Timer函数,如以下是延时100ms:
T1=Timer
Do While(Timer-T1<0.1)
X=DoEvents
LOOP
注意,用这二种方法的延时只有在延时时间>20ms以上才比较准,时间越小越不准。