徐州一中教学楼:会VB的进来看一下` 怎么弄对话框延迟?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 08:03:04
Private Sub Command1_Click()
If Text1.Text = 〃〃 And Text2.Text = 〃〃 Then
T1 = MsgBox("不能为空", vbOKOnly + vbCritical, "错误")
Exit Sub
Else
If Text1.Text = "yy5e_01" And Text2.Text = "12345" Then
T2 = MsgBox("提示说明", vbOKOnly + vbInformation, "提示")
Else
If Text1.Text = "yy5e_02" And Text2.Text = "12345" Then
T2 = MsgBox("提示说明", vbOKOnly + vbInformation, "提示")
Else
If Text1.Text = "yy5e_03" And Text2.Text = "12345" Then
T2 = MsgBox("提示说明", vbOKOnly + vbInformation, "提示")
Else
If Text1.Text = "yy5e_04" And Text2.Text = "12345" Then
T2 = MsgBox("提示说明", vbOKOnly + vbInformation, "提示")
Else
If Text1.Text = "yy5e_05" And Text2.Text = "12345" Then
T2 = MsgBox("提示说明", vbOKOnly + vbInformation, "提示")
Else
T1 = MsgBox("提示说明", vbOKOnly + vbCritical, "错误")
Text1.Text = 〃〃
Text2.Text = 〃〃
End If
End If
End If
End If
End If
End Sub
Private Sub Form_Load()
Dim X As Long
Dim Y As Long

X = Screen.Width
Y = Screen.Height
X = (X - Me.Width) / 2
Y = (Y - Me.Height) / 2
Me.Move X, Y
End Sub

---------------------------------------------------------------
怎么把
T2 = MsgBox("提示说明", vbOKOnly + vbInformation, "提示")
这个提示框延迟5秒后出现啊?
请写详细一些` 拜托了!!

给你个例子,到时调用DelayTime函数就可以了

Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long

' DelayNum为延时的毫秒数
Private Sub DelayTime(ByVal DelayNum As Long)
Dim Ctr1, Ctr2, Freq As Currency
Dim Count As Double

If QueryPerformanceFrequency(Freq) Then
QueryPerformanceCounter Ctr1
Do
QueryPerformanceCounter Ctr2
Loop While (Ctr2 - Ctr1) / Freq * 1000 < DelayNum
Else
MsgBox "不支持高精度计数器!"
End If
End Sub

Private Sub Command1_Click()
DelayTime 5000
MsgBox "Hello"
End Sub

用timer控件也可以

不推荐一楼的算法,占用大量系统资源,换句话说,运行时CPU使用量为100%左右

推荐SLEEP这个API函数,基本不占用系统资源

Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

参数只有一个,延迟时间

直接复制上面的声明到模块,就可以用了

放个闹钟控件撒

加timer控件 并关闭自动运行 时间间隔设置成5000
在要调用
T2 = MsgBox("提示说明", vbOKOnly + vbInformation, "提示")
的位置 开启timer控件的运行
在timer控件事件里写
T2 = MsgBox("提示说明", vbOKOnly + vbInformation, "提示")
同时T2要设置成全局变量
ok