我有以下代碼:VB - 顯示MSGBOX一次時間(R)
Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim mesaj As New Integer
My.Computer.Network.DownloadFile("http://rotutorial.net/anunt.txt", "c:\classmate\msg1.txt", "", "", False, 60000, True)
Dim readtext As New System.IO.StreamReader("c:\classmate\msg1.txt")
Dim text As String
text = readtext.ReadToEnd
readtext.Close()
Dim parti(10) As String
parti = text.Split("_")
Dim writetext1 As New System.IO.StreamReader("c:\classmate\msg.txt")
Dim text1 As String
Dim parti1(10) As String
text1 = writetext1.ReadToEnd
parti1 = text1.Split("_")
writetext1.Close()
Dim unic As New Integer
unic = Val(parti(0))
Dim unic1 As New Integer
unic1 = Val(parti1(0))
If unic <> unic1 Then
If unic <> unic1 Then
mesaj = MsgBox(parti(3), vbYesNo, "Mesaj")
End If
Dim writetext2 As New System.IO.StreamWriter("c:\classmate\msg.txt")
Dim text2 As String
text2 = text & "/" & text1
writetext2.Write(text2)
writetext2.Close()
Timer1.Enabled = False
Timer1.Enabled = True
End If
Timer1.Enabled = False
Timer1.Enabled = True
End Sub
計時器間隔被設定爲5000(5秒),但每次當計時器滴答作響的MSGBOX出現在屏幕上,但文件msg.txt正在寫入一次。所以,定時器檢查unic是否與unic1不同,如果不同,則會顯示一個msg框,並在msg.txt中寫入新行,但在下一個定時器tick時,即使unic和unic1等於msgbox無論如何都會出現,但它更有趣,因爲它不會再次寫入文件,只會顯示msgbox。我不明白這一點。
對不起,我英語不好,我來自羅馬尼亞。
謝謝!
所以問題是:'第二個定時器Tick事件顯示一個msgbox和你不確定的原因。我認爲這與你沒有調試代碼有關。我建議在'If unic <> unic1 Then'行(我不確定哪一個你有它列出兩次?!?!),然後在第二個事件步驟中通過代碼的條件斷點來找出爲什麼'即使unic和unic1相同,msgbox也會顯示。 –