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.GetResponseS tream)
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 6 1521
How about giving us some information about the exception that was thrown?
Since you know where it crashes, put that code in a Try...Catch statement.
Catch the exception and get it's type if need be.
"Bryan" <an*******@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com... 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.GetResponseS tream) 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
How about giving us some information about the exception that was thrown?
Since you know where it crashes, put that code in a Try...Catch statement.
Catch the exception and get it's type if need be.
"Bryan" <an*******@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com... 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.GetResponseS tream) 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
Here is the error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object
Source Error:
Line 23: If ReadandWrite The
Line 24: Scrape = strFil
Line 25: file.Close() 'Error occurs her
Line 26: Return Scrap
Line 27: End I
Source File: c:\inetpub\wwwroot\CompetitorKiller\ScreenScraper. vb Line: 25
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.
CompetitorKiller.ScreenScraper.Scrape(String URL, Boolean ReadandWrite, String FileType) in c:\inetpub\wwwroot\CompetitorKiller\ScreenScraper. vb:2
CompetitorKiller.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\CompetitorKiller\WebForm1.aspx. vb:3
System.Web.UI.WebControls.Button.OnClick(EventArgs e
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData
System.Web.UI.Page.ProcessRequestMain(
Here is the error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object
Source Error:
Line 23: If ReadandWrite The
Line 24: Scrape = strFil
Line 25: file.Close() 'Error occurs her
Line 26: Return Scrap
Line 27: End I
Source File: c:\inetpub\wwwroot\CompetitorKiller\ScreenScraper. vb Line: 25
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.
CompetitorKiller.ScreenScraper.Scrape(String URL, Boolean ReadandWrite, String FileType) in c:\inetpub\wwwroot\CompetitorKiller\ScreenScraper. vb:2
CompetitorKiller.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\CompetitorKiller\WebForm1.aspx. vb:3
System.Web.UI.WebControls.Button.OnClick(EventArgs e
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData
System.Web.UI.Page.ProcessRequestMain(
Your code doesn't make sense.
Change this line
Select Case URL
to read this:
Select Case FileType
I tried your code this way and it worked perfectly. Your select case
never selected any statement. That's why you got an error. Your
filestream was never craeted.
Bryan wrote: Here is the error: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 23: If ReadandWrite Then Line 24: Scrape = strFile Line 25: file.Close() 'Error occurs here Line 26: Return Scrape Line 27: End If
Source File: c:\inetpub\wwwroot\CompetitorKiller\ScreenScraper. vb Line: 25
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] CompetitorKiller.ScreenScraper.Scrape(String URL, Boolean ReadandWrite, String FileType) in c:\inetpub\wwwroot\CompetitorKiller\ScreenScraper. vb:25 CompetitorKiller.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\CompetitorKiller\WebForm1.aspx. vb:39 System.Web.UI.WebControls.Button.OnClick(EventArgs e) System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) System.Web.UI.Page.ProcessRequestMain()
Your code doesn't make sense.
Change this line
Select Case URL
to read this:
Select Case FileType
I tried your code this way and it worked perfectly. Your select case
never selected any statement. That's why you got an error. Your
filestream was never craeted.
Bryan wrote: Here is the error: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 23: If ReadandWrite Then Line 24: Scrape = strFile Line 25: file.Close() 'Error occurs here Line 26: Return Scrape Line 27: End If
Source File: c:\inetpub\wwwroot\CompetitorKiller\ScreenScraper. vb Line: 25
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] CompetitorKiller.ScreenScraper.Scrape(String URL, Boolean ReadandWrite, String FileType) in c:\inetpub\wwwroot\CompetitorKiller\ScreenScraper. vb:25 CompetitorKiller.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\CompetitorKiller\WebForm1.aspx. vb:39 System.Web.UI.WebControls.Button.OnClick(EventArgs e) System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) System.Web.UI.Page.ProcessRequestMain() This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: YGeek |
last post by:
Is there any difference between declaring a variable at the top of a method
versus in the code of the method? Is there a performance impact for either
choice? What about if the method will return...
|
by: Grant Wagner |
last post by:
Given the following working code:
function attributes() {
var attr1 = arguments || '_';
var attr2 = arguments || '_';
return (
function (el1, el2) {
var value1 = el1 + el1;
var value2 = el2...
|
by: Gery D. Dorazio |
last post by:
Gurus,
If a static variable is defined in a class what is the scope of the variable
resolved to for it to remain 'static'? For instance, lets say I create a
class library assembly that is...
|
by: Russ Chinoy |
last post by:
Hi,
This may be a totally newbie question, but I'm stumped.
If I have a function such as:
function DoSomething(strVarName) {
.....
}
|
by: pbmods |
last post by:
VARIABLE SCOPE IN JAVASCRIPT
LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN )
PREREQS: VARIABLES
First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
|
by: MMcCarthy |
last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
|
by: Shraddha |
last post by:
Can we declare extern variable as static?
What will be the scope of the variable then? What if we change the
value of the variable in some other function?
Also can someone tell me that if we can...
|
by: somenath |
last post by:
Hi All ,
I have one question regarding scope and lifetime of variable.
#include <stdio.h>
int main(int argc, char *argv)
{
int *intp = NULL;
char *sptr = NULL;
|
by: istillshine |
last post by:
When I control if I print messages, I usually use a global variable
"int silent". When I set "-silent" flag in my command line
parameters, I set silent = 1 in my main.c.
I have many functions...
|
by: SRoubtsov |
last post by:
Dear all,
Do you know whether ANSI C (or some other dialects) support the
following:
* a variable name coincides with a type name,
* a structure/union field name coincides with a type name
in...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |