Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Object variable or With block variable not set
Message
From
23/01/2011 05:04:18
 
 
To
22/01/2011 15:09:29
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01497018
Message ID:
01497047
Views:
43
>This page details some possibiltiies of obtaining the famous "Object variable or With block variable not set " error:
>
>http://msdn.microsoft.com/en-us/library/5szkzs17(v=vs.80).aspx
>
>In my code, one of the standard is to always initialize everything to a default value. So, here is an example:
>
>
>        Dim lcHtml As String = ""
>        Dim ldAddDate As Date = Nothing
>        Dim llBlankDate As Boolean = False
>        Dim llForceGive As Boolean = False
>        Dim llHelpGive As Boolean = False
>        Dim llHelpRemove As Boolean = False
>        Dim llIn As Boolean = False
>        Dim llPrevious As Boolean = False
>        Dim llReply As Boolean = False
>        Dim llSolution As Boolean = False
>        Dim llSolutionGive As Boolean = False
>        Dim llSolutionRemove As Boolean = False
>        Dim llSolutionSysop As Boolean = False
>        Dim llUnmarkSysop As Boolean = False
>        Dim lnCounter As Integer = 0
>        Dim lnLocation As Integer = 0
>        Dim lnNoReply As Integer = 0
>        Dim lnOriginalMember As Integer = 0
>        Dim lnPoint As Integer = 0
>        Dim lnUnmarkSysop As Integer = 0
>        Dim lnUserHeadNoReply As Integer = 0
>        Dim loControlLabel As System.Web.UI.WebControls.Label = New System.Web.UI.WebControls.Label
>        Dim loControlLiteral As System.Web.UI.WebControls.Literal = New System.Web.UI.WebControls.Literal
>        Dim loControlTable As System.Web.UI.WebControls.Table = New System.Web.UI.WebControls.Table
>        Dim loDataProvider As Framework.Framework.Data = New Framework.Framework.Data(oProcess)
>        Dim loRow As DataRow = Nothing
>        Dim loUpdate As Framework.Framework.Update = New Framework.Framework.Update(oProcess)
>
>
>But, referring to that page, point #2 says to make sure to not use an object variable set to Nothing.
>
>I have a situation that happens once every one hundred thousand this approximately. So, it is very difficult to simulate. So, I cannot locate exactly where it happens. But, this error reported is within the biggest transaction being executed on this site. Basically, it is being done between 5000 to 10000 times a day. So, in regards to Nothing, could it be that the following line could cause this from time to time:
>
>
>        Dim loRow As DataRow = Nothing
>
>
>As I said, this hit works ok but once every hundred thousand hits approximately, it will generate an error. But, executing the page as is, will work at 99.99% of the time.
>
>If this could be related to this line, then it is a bad bug, already reported by Microsoft, which should be fixed soon. Because, when not doing so, assuming just like this:
>
>
>        Dim loRow As DataRow
>
>
>This creates some green warning which is irritating me if I have defined a variable which is not being used.

All .net types have default values. An integer, for example, defaults to 0 ; any object to a null value (Nothing in VB)
So there is absolutely no difference between 'Dim loRow As DataRow' and 'Dim loRow As DataRow = Nothing' except the warning in the IDE. And it *is* only that - just a reminder that you may have intended to assign a value to it at that point or later. The choice of syntax there can have no bearing on the cause of the error since whether you explicitly assign the null value or let the compiler do it for you the outcome is the same.

If the error is related to a DataRow you need to look at where it should be assigned an actual value. Maybe you are somehow trying to select a row that doesn't exist?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform