VB常見(jiàn)問(wèn)題解答(1)
發(fā)布時(shí)間:2008-08-05 閱讀數(shù): 次 來(lái)源:網(wǎng)樂(lè)原科技
問(wèn):在一個(gè)床體中設(shè)置了2個(gè)命令按鈕,Command1,Command2。Commamd1執(zhí)行一個(gè)費(fèi)時(shí)的操作,包括調(diào)用多個(gè)過(guò)程和函數(shù),而Command2則是終止/暫停Command1的運(yùn)行,不是退出該程序,不知用VB5.0如何解決?
答:你可以采用一種變通的方法,在程序中定義一個(gè)Boolean變量,在執(zhí)行command1中的程序時(shí)監(jiān)視該變量,如果為False退出程序,在command2中加入代碼,只要點(diǎn)擊command2就將該變量設(shè)置為False下面是例程
Dim bMark As Boolean
Private Sub Command1_Click()
bMark = True
For I = 1 To 150000 ' Start loop.
DoEvents ' Yield to operating system.
Text1.Text = Str(I)
If Not bMark Then
Exit Sub
End If
Next I ' Increment loop counter
End Sub
Private Sub Command2_Click()
bMark = False
End Sub
問(wèn):有位大俠編了如下代碼:
Private Sub cmdCalendar_Click()
Dim UserDate As Date
UserDate = CVDate(txtDate)
If frmCalendar.GetDate(UserDate) Then
txtDate = UserDate
End If
End Sub-