Getting text from a .txt file on web

Lanc1988

Contributor
Joined
Nov 27, 2003
Messages
508
I am trying to use the following code to get whats from a txt file on my website when the user clicks the button the code is in and then if the number in the code is greater than the number in a label on the form then it does something, if its less than or equal to the number in the label it does something else..

But it doesn't seem to be working for me, it has to be something pretty simple I have wrong:
Visual Basic:
        Dim CurrentVersion As String
        On Error Resume Next
        Dim srCurrentVersion As System.IO.StreamReader = _
            New System.IO.StreamReader("http://www.rs-sidekick.com/Client/CurrentVersion.txt")
        Dim line, vals() As String
        Do
            line = srCurrentVersion.ReadLine
            If line Is Nothing Then Exit Do
            vals = line.Split(vbTab)
            CurrentVersion = vals(0)
        Loop
        srCurrentVersion.Close()
        srCurrentVersion = Nothing

        If CurrentVersion > lblMyVersion.Text Then
            MessageBox.Show("Newer version is available!")
        End If
        If CurrentVersion <= lblMyVersion.Text Then
            MessageBox.Show("You have the newest version of RS SideKick.")
        End If
 
IIRC you cannot open a URL directly from a StreamReader - however the WebClient class will return a stream that you can use with a stream reader.
Visual Basic:
        Dim CurrentVersion As String
        On Error Resume Next
        Dim srCurrentVersion As System.IO.StreamReader

        Dim wc As New System.Net.WebClient

        srCurrentVersion = New System.IO.StreamReader(wc.OpenRead("http://www.rs-sidekick.com/Client/CurrentVersion.txt"))

        Dim line, vals() As String
        Do
            line = srCurrentVersion.ReadLine
            If line Is Nothing Then Exit Do
            vals = line.Split(vbTab)
            CurrentVersion = vals(0)
        Loop
        srCurrentVersion.Close()
        srCurrentVersion = Nothing

        If CurrentVersion > lblMyVersion.Text Then
            MessageBox.Show("Newer version is available!")
        End If
        If CurrentVersion <= lblMyVersion.Text Then
            MessageBox.Show("You have the newest version of RS SideKick.")
        End If
 
IIRC this way takes a lot of memory up, for some reason... not sure though, just what i remember

*EDIT* i was refering to the first reply
 
Back
Top