Function GetPage(ByVal pageUrl As String) As String
Dim s As String = ""
Try
Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
Dim response As HttpWebResponse = request.GetResponse()
Using reader As StreamReader = New StreamReader(response.GetResponseStream())
s = reader.ReadToEnd()
End Using
Catch ex As Exception
Debug.WriteLine("FAIL: " + ex.Message)
End Try
Return s
End Function
Then, Try this.
Code:
Dim url1, url2, url3, url4 As String
url1 = "http://mywebsite/TextDocument1.txt"
url2 = "http://mywebsite/TextDocument2.txt"
url3 = "http://mywebsite/TextDocument3.txt"
url4 = "http://mywebsite/TextDocument4.txt"
Dim Online1, Online2, Online3, Online4 As String
Online1 = GetPage(url1)
Online2 = GetPage(url2)
Online3 = GetPage(url3)
Online4 = GetPage(url4)
Originally Posted by FLAMESABER
First, use this function:
Code:
Function GetPage(ByVal pageUrl As String) As String
Dim s As String = ""
Try
Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
Dim response As HttpWebResponse = request.GetResponse()
Using reader As StreamReader = New StreamReader(response.GetResponseStream())
s = reader.ReadToEnd()
End Using
Catch ex As Exception
Debug.WriteLine("FAIL: " + ex.Message)
End Try
Return s
End Function
Then, Try this.
Code:
Dim url1, url2, url3, url4 As String
url1 = "http://mywebsite/TextDocument1.txt"
url2 = "http://mywebsite/TextDocument2.txt"
url3 = "http://mywebsite/TextDocument3.txt"
url4 = "http://mywebsite/TextDocument4.txt"
Dim Online1, Online2, Online3, Online4 As String
Online1 = GetPage(url1)
Online2 = GetPage(url2)
Online3 = GetPage(url3)
Online4 = GetPage(url4)
Can I have your children?
Thanks so much man, works beautifully and so much less messy Thanks.
Originally Posted by J-Deezy
Can I have your children?
Thanks so much man, works beautifully and so much less messy Thanks.
No, I love my children...lol
No problem...*cough* thnx !! ?
xD
Originally Posted by FLAMESABER
No, I love my children...lol
No problem...*cough* thnx !! ?
xD
I meant can I make you some more silly
I pressed thanks!
Originally Posted by J-Deezy
I meant can I make you some more silly
I pressed thanks!
No, you can't...and thnx
Oh wow, and thanks. haha solved tag anyone?
Hey Flame if you happen to look at this thread again, is it possible to read one line, save it to a string variable, read the next line, save it to another string variable...etc
Code:
While Not reader.EndOfStream
Dim s As String = reader.ReadLine
End While
You may do something like...
Code:
if s.startswith("abc")...
Code:
if s.contains("def")...
I don't know how to declare a new variable for each line. You may use a hidden listbox or idk...tell me exactly why/how you want to do that ^.-
Well basically what I want to do is have a few things associated to a general topic that I save in a text document.
i.e my text document is set out like this
[php]
NAME
LINK
LINK2
[/php]
But I want to read the line that contains the line and assign it to a label
then I want to read second line and assign that to another string variable
I.e (this isn't actual code obviously but I hope it helps you understand better what i mean)
[php]
Dim DocName, DocLink1, DocLink2 as string
Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
Dim response As HttpWebResponse = request.GetResponse()
Using reader As StreamReader = New StreamReader(response.GetResponseStream())
Public Shared Function ReadSpecifiedLine(ByVal file As String, ByVal lineNum As Integer) As String
'create a variable to hold the contents of the file
Dim contents As String = String.Empty
'always use a try...catch to deal
'with any exceptions that may occur
Try
Using stream As New StreamReader(file)
contents = stream.ReadToEnd().Replace(vbCr & vbLf, vbLf).Replace(vbLf & vbCr, vbLf)
Dim linesArray As String() = contents.Split(New Char() {ControlChars.Lf})
'Make sure we have ana ctual array
If linesArray.Length > 1 Then
'Make sure user didnt provide number greater than the number
'of lines in the array, and not less than 0 (zero) Thanks AdamSpeight2008
If Not lineNum > linesArray.Length AndAlso Not lineNum < 0 Then
Return linesArray(lineNum)
Else
'Failed our check so return the first line in the array
Return linesArray(0)
End If
Else
'No array so return the line
Return contents
End If
End Using
Catch ex As Exception
Return ex.ToString()
End Try
End Function
Public Shared Function ReadSpecifiedLine(ByVal file As String, ByVal lineNum As Integer) As String
'create a variable to hold the contents of the file
Dim contents As String = String.Empty
'always use a try...catch to deal
'with any exceptions that may occur
Try
Using stream As New StreamReader(file)
contents = stream.ReadToEnd().Replace(vbCr & vbLf, vbLf).Replace(vbLf & vbCr, vbLf)
Dim linesArray As String() = contents.Split(New Char() {ControlChars.Lf})
'Make sure we have ana ctual array
If linesArray.Length > 1 Then
'Make sure user didnt provide number greater than the number
'of lines in the array, and not less than 0 (zero) Thanks AdamSpeight2008
If Not lineNum > linesArray.Length AndAlso Not lineNum < 0 Then
Return linesArray(lineNum)
Else
'Failed our check so return the first line in the array
Return linesArray(0)
End If
Else
'No array so return the line
Return contents
End If
End Using
Catch ex As Exception
Return ex.ToString()
End Try
End Function