G
Guest
I have the following and am crashing at the specified line. I've declared Function Globals which should extend the scope of a variable to the end of the funtion. But it seems that my varaiables are ending at the end of the case statement. They shouldn't be. I'm really starting to wondering if I found a bug being that the variables have been declared Globally.
Public Function Scrape(ByVal URL As String, ByVal ReadandWrite As Boolean, ByVal FileType As String) As Object
Dim objWebRequest As System.Net.HttpWebRequest
Dim objWebResponse As System.Net.HttpWebResponse
Dim file As System.IO.StreamReader
Dim strFile As String
Select Case URL
Case "Text File"
file = New System.IO.StreamReader(URL)
Case "URL File"
objWebRequest = CType(System.Net.WebRequest.Create(URL), System.Net.HttpWebRequest)
objWebRequest.Method = "GET"
objWebResponse = CType(objWebRequest.GetResponse(), System.Net.HttpWebResponse)
file = New System.IO.StreamReader(objWebResponse.GetResponseStream)
End Select
'Program crashes right here.
strFile = file.ReadToEnd
If ReadandWrite Then
Scrape = strFile
'Program crashes here too if the above line was set in the Global as 'Dim strFile as String = file.ReadToEnd
file.Close()
Return Scrape
End If
Public Function Scrape(ByVal URL As String, ByVal ReadandWrite As Boolean, ByVal FileType As String) As Object
Dim objWebRequest As System.Net.HttpWebRequest
Dim objWebResponse As System.Net.HttpWebResponse
Dim file As System.IO.StreamReader
Dim strFile As String
Select Case URL
Case "Text File"
file = New System.IO.StreamReader(URL)
Case "URL File"
objWebRequest = CType(System.Net.WebRequest.Create(URL), System.Net.HttpWebRequest)
objWebRequest.Method = "GET"
objWebResponse = CType(objWebRequest.GetResponse(), System.Net.HttpWebResponse)
file = New System.IO.StreamReader(objWebResponse.GetResponseStream)
End Select
'Program crashes right here.
strFile = file.ReadToEnd
If ReadandWrite Then
Scrape = strFile
'Program crashes here too if the above line was set in the Global as 'Dim strFile as String = file.ReadToEnd
file.Close()
Return Scrape
End If