我有以下代码: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也会显示。 –