我有以下代码:
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 中写入新行,但在下一个计时器滴答时,即使 unic 和 unic1 等于 msgbox无论如何都会出现,但它更有趣,因为它不会再次写入文件,只会显示 msgbox。我不明白这一点。
抱歉我的英语不好,我来自罗马尼亚。
谢谢!