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.Http WebRequest
Dim objWebResponse As System.Net.Http WebResponse
Dim file As System.IO.Strea mReader
Dim strFile As String
Select Case URL
Case "Text File"
file = New System.IO.Strea mReader(URL)
Case "URL File"
objWebRequest = CType(System.Ne t.WebRequest.Cr eate(URL), System.Net.Http WebRequest)
objWebRequest.M ethod = "GET"
objWebResponse = CType(objWebReq uest.GetRespons e(), System.Net.Http WebResponse)
file = New System.IO.Strea mReader(objWebR esponse.GetResp onseStream)
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.Http WebRequest
Dim objWebResponse As System.Net.Http WebResponse
Dim file As System.IO.Strea mReader
Dim strFile As String
Select Case URL
Case "Text File"
file = New System.IO.Strea mReader(URL)
Case "URL File"
objWebRequest = CType(System.Ne t.WebRequest.Cr eate(URL), System.Net.Http WebRequest)
objWebRequest.M ethod = "GET"
objWebResponse = CType(objWebReq uest.GetRespons e(), System.Net.Http WebResponse)
file = New System.IO.Strea mReader(objWebR esponse.GetResp onseStream)
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
Comment