|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Object Variable or With block variable not set.I get this error whenever I close one particular form in my Windows
application; however, I can't find the error in the code. Setting a break on the dispose event doesn't catch it and the error does not occur on any other event on the form. I've unchecked the 'My Code only' debug option, but I still can't catch this error. Any suggestions? Thanks. Ross I haven't seen this error since VB 6. Do you have option strict turned on
(if this is a VB .NET app)? Show quote "Ross Culver" <rcul***@warrenalloy.com> wrote in message news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >I get this error whenever I close one particular form in my Windows >application; however, I can't find the error in the code. Setting a break >on the dispose event doesn't catch it and the error does not occur on any >other event on the form. I've unchecked the 'My Code only' debug option, >but I still can't catch this error. > > Any suggestions? > > Thanks. > > Ross > VS2K5, Option Strict was Off.
Show quote "Scott M." <s-mar@nospam.nospam> wrote in message news:eeNqb7mEIHA.4296@TK2MSFTNGP04.phx.gbl... >I haven't seen this error since VB 6. Do you have option strict turned on >(if this is a VB .NET app)? > > > "Ross Culver" <rcul***@warrenalloy.com> wrote in message > news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >>I get this error whenever I close one particular form in my Windows >>application; however, I can't find the error in the code. Setting a break >>on the dispose event doesn't catch it and the error does not occur on any >>other event on the form. I've unchecked the 'My Code only' debug option, >>but I still can't catch this error. >> >> Any suggestions? >> >> Thanks. >> >> Ross >> > > Just for hoots, I changed the Option Explicit, Option Strict settings to
every possible combination. None resolved this problem. Ross Show quote "Scott M." <s-mar@nospam.nospam> wrote in message news:eeNqb7mEIHA.4296@TK2MSFTNGP04.phx.gbl... >I haven't seen this error since VB 6. Do you have option strict turned on >(if this is a VB .NET app)? > > > "Ross Culver" <rcul***@warrenalloy.com> wrote in message > news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >>I get this error whenever I close one particular form in my Windows >>application; however, I can't find the error in the code. Setting a break >>on the dispose event doesn't catch it and the error does not occur on any >>other event on the form. I've unchecked the 'My Code only' debug option, >>but I still can't catch this error. >> >> Any suggestions? >> >> Thanks. >> >> Ross >> > > You should always work with Option Explicit and Option Strict set to ON
(explicit is on by default but strict if off by default). With Option Strict On you are forced to write more succinct code, but the payoff is less runtime errors. I was hoping that by turning it on, you'd see your error during the build. This error simply means that you have a variable that is referring to an ojbect that has not been instantiated, like this: Dim sb As System.Text.StringBuilder sb.Append("Test") In this case sb is just a variable refering to a memory address that "will eventually" hold an actual instance of a StringBuilder, but without the keyword "New" in the declaration line, you don't actually have an instance of one, thus you have an "Object reference not set to an instance of an object." Setting a break on dispose wouldn't catch the problem because dispose occurs so late in the process. I'd set a breakpoint in the Load event and then step through the normal usage of the form, you'll find the error when you close the form. -Scott Show quote "Ross Culver" <rcul***@warrenalloy.com> wrote in message news:uD1nwCnEIHA.5208@TK2MSFTNGP04.phx.gbl... > Just for hoots, I changed the Option Explicit, Option Strict settings to > every possible combination. None resolved this problem. > > Ross > > > "Scott M." <s-mar@nospam.nospam> wrote in message > news:eeNqb7mEIHA.4296@TK2MSFTNGP04.phx.gbl... >>I haven't seen this error since VB 6. Do you have option strict turned on >>(if this is a VB .NET app)? >> >> >> "Ross Culver" <rcul***@warrenalloy.com> wrote in message >> news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >>>I get this error whenever I close one particular form in my Windows >>>application; however, I can't find the error in the code. Setting a >>>break on the dispose event doesn't catch it and the error does not occur >>>on any other event on the form. I've unchecked the 'My Code only' debug >>>option, but I still can't catch this error. >>> >>> Any suggestions? >>> >>> Thanks. >>> >>> Ross >>> >> >> > > "Ross Culver" <rcul***@warrenalloy.com> wrote in message You have a With statement with no end-with or the other way around. Or you news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >I get this error whenever I close one particular form in my Windows >application; however, I can't find the error in the code. Setting a break >on the dispose event doesn't catch it and the error does not occur on any >other event on the form. I've unchecked the 'My Code only' debug option, >but I still can't catch this error. > are dereferencing an object variable that was never initialized. You'll notice the words (not set). I'll assume this is VB.Net Debug->Exceptions Select "Common Runtime Exceptions" Caption at top of screen "Break when an exception is: and you will select *Thrown*, This is a break on *All Errors*. Actually, this line of code is the problem:
DocType = CType(Me.lbSearchDocType.SelectedItem(0).ToString, Integer) DocType has been declared public integer. The lbSearchDocType is a simple Windows listbox with selection mode set to 'One'. The code does return the correct value, so why do I get this error when closing the form? Ross Show quote "Mr. Arnold" <MR. Arn***@Arnold.com> wrote in message news:O1efoDyEIHA.5648@TK2MSFTNGP05.phx.gbl... > > "Ross Culver" <rcul***@warrenalloy.com> wrote in message > news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >>I get this error whenever I close one particular form in my Windows >>application; however, I can't find the error in the code. Setting a break >>on the dispose event doesn't catch it and the error does not occur on any >>other event on the form. I've unchecked the 'My Code only' debug option, >>but I still can't catch this error. >> > > You have a With statement with no end-with or the other way around. Or you > are dereferencing an object variable that was never initialized. You'll > notice the words (not set). I'll assume this is VB.Net > > Debug->Exceptions > > Select "Common Runtime Exceptions" > > Caption at top of screen "Break when an exception is: and you will > select *Thrown*, This is a break on *All Errors*. > > > > Where is that line of code? I would guess that the error occurs
because at the time that line is executed the listbox has no item selected. Since you don't mention the debugger, I assume this happens when running a Release build. Does it fail when run under the debugger? On Mon, 22 Oct 2007 12:38:14 -0500, "Ross Culver" <rcul***@warrenalloy.com> wrote: Show quote >Actually, this line of code is the problem: > >DocType = CType(Me.lbSearchDocType.SelectedItem(0).ToString, Integer) > >DocType has been declared public integer. The lbSearchDocType is a simple >Windows listbox with selection mode set to 'One'. > >The code does return the correct value, so why do I get this error when >closing the form? > >Ross > > >"Mr. Arnold" <MR. Arn***@Arnold.com> wrote in message >news:O1efoDyEIHA.5648@TK2MSFTNGP05.phx.gbl... >> >> "Ross Culver" <rcul***@warrenalloy.com> wrote in message >> news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >>>I get this error whenever I close one particular form in my Windows >>>application; however, I can't find the error in the code. Setting a break >>>on the dispose event doesn't catch it and the error does not occur on any >>>other event on the form. I've unchecked the 'My Code only' debug option, >>>but I still can't catch this error. >>> >> >> You have a With statement with no end-with or the other way around. Or you >> are dereferencing an object variable that was never initialized. You'll >> notice the words (not set). I'll assume this is VB.Net >> >> Debug->Exceptions >> >> Select "Common Runtime Exceptions" >> >> Caption at top of screen "Break when an exception is: and you will >> select *Thrown*, This is a break on *All Errors*. >> >> >> >> > It's in the SelectedIndexChanged event. Go figure!
Ross Show quote "Jack Jackson" <jacknospam@pebbleridge.com> wrote in message news:k1pph3dro89vu2djp9vosu2clu4oiu9p5d@4ax.com... > Where is that line of code? I would guess that the error occurs > because at the time that line is executed the listbox has no item > selected. > > Since you don't mention the debugger, I assume this happens when > running a Release build. Does it fail when run under the debugger? > > On Mon, 22 Oct 2007 12:38:14 -0500, "Ross Culver" > <rcul***@warrenalloy.com> wrote: > >>Actually, this line of code is the problem: >> >>DocType = CType(Me.lbSearchDocType.SelectedItem(0).ToString, Integer) >> >>DocType has been declared public integer. The lbSearchDocType is a simple >>Windows listbox with selection mode set to 'One'. >> >>The code does return the correct value, so why do I get this error when >>closing the form? >> >>Ross >> >> >>"Mr. Arnold" <MR. Arn***@Arnold.com> wrote in message >>news:O1efoDyEIHA.5648@TK2MSFTNGP05.phx.gbl... >>> >>> "Ross Culver" <rcul***@warrenalloy.com> wrote in message >>> news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >>>>I get this error whenever I close one particular form in my Windows >>>>application; however, I can't find the error in the code. Setting a >>>>break >>>>on the dispose event doesn't catch it and the error does not occur on >>>>any >>>>other event on the form. I've unchecked the 'My Code only' debug >>>>option, >>>>but I still can't catch this error. >>>> >>> >>> You have a With statement with no end-with or the other way around. Or >>> you >>> are dereferencing an object variable that was never initialized. You'll >>> notice the words (not set). I'll assume this is VB.Net >>> >>> Debug->Exceptions >>> >>> Select "Common Runtime Exceptions" >>> >>> Caption at top of screen "Break when an exception is: and you will >>> select *Thrown*, This is a break on *All Errors*. >>> >>> >>> >>> >> You didn't answer the rest of my questions. Does this not happen when
run under the debugger? I still think it happens because the code expects there to be something selected in the listbox. If nothing is selected this is what will happen. Either put a breakpoint on the line and see what lbSearchDocType.SelectedItem.Count is, or change the code to: If Me.lbSearchDocType.Count > 0 Then DocType = CType(Me.lbSearchDocType.SelectedItem(0).ToString, Integer) ... other code that processes DocTyipe EndIf On Mon, 22 Oct 2007 13:04:18 -0500, "Ross Culver" <rcul***@warrenalloy.com> wrote: Show quote >It's in the SelectedIndexChanged event. Go figure! > >Ross > >"Jack Jackson" <jacknospam@pebbleridge.com> wrote in message >news:k1pph3dro89vu2djp9vosu2clu4oiu9p5d@4ax.com... >> Where is that line of code? I would guess that the error occurs >> because at the time that line is executed the listbox has no item >> selected. >> >> Since you don't mention the debugger, I assume this happens when >> running a Release build. Does it fail when run under the debugger? >> >> On Mon, 22 Oct 2007 12:38:14 -0500, "Ross Culver" >> <rcul***@warrenalloy.com> wrote: >> >>>Actually, this line of code is the problem: >>> >>>DocType = CType(Me.lbSearchDocType.SelectedItem(0).ToString, Integer) >>> >>>DocType has been declared public integer. The lbSearchDocType is a simple >>>Windows listbox with selection mode set to 'One'. >>> >>>The code does return the correct value, so why do I get this error when >>>closing the form? >>> >>>Ross >>> >>> >>>"Mr. Arnold" <MR. Arn***@Arnold.com> wrote in message >>>news:O1efoDyEIHA.5648@TK2MSFTNGP05.phx.gbl... >>>> >>>> "Ross Culver" <rcul***@warrenalloy.com> wrote in message >>>> news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >>>>>I get this error whenever I close one particular form in my Windows >>>>>application; however, I can't find the error in the code. Setting a >>>>>break >>>>>on the dispose event doesn't catch it and the error does not occur on >>>>>any >>>>>other event on the form. I've unchecked the 'My Code only' debug >>>>>option, >>>>>but I still can't catch this error. >>>>> >>>> >>>> You have a With statement with no end-with or the other way around. Or >>>> you >>>> are dereferencing an object variable that was never initialized. You'll >>>> notice the words (not set). I'll assume this is VB.Net >>>> >>>> Debug->Exceptions >>>> >>>> Select "Common Runtime Exceptions" >>>> >>>> Caption at top of screen "Break when an exception is: and you will >>>> select *Thrown*, This is a break on *All Errors*. >>>> >>>> >>>> >>>> >>> > I couldn't figure it out, so I just put "'Do nothing" in the catch phrase to
ignore the error. Ross Show quote "Ross Culver" <rcul***@warrenalloy.com> wrote in message news:ea46LdmEIHA.1212@TK2MSFTNGP05.phx.gbl... >I get this error whenever I close one particular form in my Windows >application; however, I can't find the error in the code. Setting a break >on the dispose event doesn't catch it and the error does not occur on any >other event on the form. I've unchecked the 'My Code only' debug option, >but I still can't catch this error. > > Any suggestions? > > Thanks. > > Ross > |
|||||||||||||||||||||||