Problem with Streamreader and Notify Icon Tip
im having problem with this code, what i want it to do it go on the site nd if it finds the word online it switches the text
so say it directed to google and the word online is somewhere in the html code of the site, the app should then change label 5 to online
BUT i get this error
"Could not find file 'C:\Users\Owner\Desktop\AMi BETA\AMi BETA\bin\Debug\www.google.com'."
-----------------------
everything i want the notifyicon to do is working but i only want it to pop up once but every time the timer ticks it pops up
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ServerStatus.Tick
Dim LB5 As String = Label5.Text
Dim wc As New System.Net.WebClient()
Dim sr As New IO.StreamReader(wc.OpenRead(LB5))
Dim s As String = sr.ReadToEnd()
sr.Close()
If s.Contains("Online") Then
Status.Text = "Online"
Status.ForeColor = Color.LimeGreen
If Me.Visible = False Then
'Tip Pops up
NotifyIcon1.BalloonTipText = Label1.Text & " is Online!"
NotifyIcon1.ShowBalloonTip(5000)
End If
Else
Me.Status.Text = "Offline"
Status.ForeColor = Color.Red
End If
End Sub
Re: Problem with Streamreader and Notify Icon Tip
Re: Problem with Streamreader and Notify Icon Tip
You're doing it wrong...
You need to download/open the URL, so you can use the method OpenRead with a string...
Example adapted from MSDN.
vb.net Code:
Dim client As New WebClient()
Dim pageData As [Byte]() = client.DownloadData(Label5.Text)
Dim s As String = Encoding.ASCII.GetString(pageData)
Re: Problem with Streamreader and Notify Icon Tip
sorry i have no clue what do do with that i put it in and i got the same error
Re: Problem with Streamreader and Notify Icon Tip
That can't find www.google.com?!!?
vb.net Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ServerStatus.Tick
Dim client As New WebClient()
Dim pageData As [Byte]() = client.DownloadData(Label5.Text)
Dim s As String = Encoding.ASCII.GetString(pageData)
If s.Contains("Online") Then
Status.Text = "Online"
Status.ForeColor = Color.LimeGreen
If Me.Visible = False Then
'Tip Pops up
NotifyIcon1.BalloonTipText = Label1.Text & " is Online!"
NotifyIcon1.ShowBalloonTip(5000)
End If
Else
Status.Text = "Offline"
Status.ForeColor = Color.Red
End If
End Sub
1 Attachment(s)
Re: Problem with Streamreader and Notify Icon Tip
Quote:
Originally Posted by
mickey_pt
That can't find
www.google.com?!!?
vb.net Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ServerStatus.Tick
Dim client As New WebClient()
Dim pageData As [Byte]() = client.DownloadData(Label5.Text)
Dim s As String = Encoding.ASCII.GetString(pageData)
If s.Contains("Online") Then
Status.Text = "Online"
Status.ForeColor = Color.LimeGreen
If Me.Visible = False Then
'Tip Pops up
NotifyIcon1.BalloonTipText = Label1.Text & " is Online!"
NotifyIcon1.ShowBalloonTip(5000)
End If
Else
Status.Text = "Offline"
Status.ForeColor = Color.Red
End If
End Sub
i get a error
the google thing was just a example
Re: Problem with Streamreader and Notify Icon Tip
You need to import the namespaces or to put the complete code...
vb.net Code:
Imports System.Net
Imports System.Text
or
vb.net Code:
Dim client As New System.Net.WebClient()
Dim s As String = System.Text.Encoding.ASCII.GetString(pageData)
1 Attachment(s)
Re: Problem with Streamreader and Notify Icon Tip
Quote:
Originally Posted by
mickey_pt
You need to import the namespaces or to put the complete code...
vb.net Code:
Imports System.Net
Imports System.Text
or
vb.net Code:
Dim client As New System.Net.WebClient()
Dim s As String = System.Text.Encoding.ASCII.GetString(pageData)
same error :(
Re: Problem with Streamreader and Notify Icon Tip
Just put in the label http://www.google.com, don't forget the http://
Re: Problem with Streamreader and Notify Icon Tip
Thankyouuu >.<
do you know how to fix the notifyicon tip?
Re: Problem with Streamreader and Notify Icon Tip
bump, i just need to find out the problem with the notifyicon now
Re: Problem with Streamreader and Notify Icon Tip
Re: Problem with Streamreader and Notify Icon Tip
Code:
If s.Contains("Online") Then
Status.Text = "Online"
Status.ForeColor = Color.LimeGreen
If Me.Visible = False Then
'Tip Pops up
NotifyIcon1.BalloonTipText = Label1.Text & " is Online!"
NotifyIcon1.ShowBalloonTip(5000)
End If
Else
Me.Status.Text = "Offline"
Status.ForeColor = Color.Red
End If
thats the problem, when the program is in the taskbar it spams the notifyicon and i only what it to pop up once for evey time it changes from offline to online
Re: Problem with Streamreader and Notify Icon Tip
Use a var to save the last state, and then in the tick event, check if the current state it's like the last state, if it's equal don't do anything, if not, show the notify icon and set the last state equals to the current state...