Re: Beginner level VB.NET question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Anand[MVP]" <AnandMVP@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:342C12FC-6C50-4872-A8C3-F85DE1EA5C6C@xxxxxxxxxxxxxxxx
As such the code seems OK, but I just want to check, as you did mention you
were a C# programmer. VB is not case sensitive. So are you just setting the
object to nothing somewhere in the code, but not realizing it is the same
object?

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com


"OregonMike" wrote:



I'm a C# guy tasked with fixing some bugs in VB.NET code. I've run
into something that doesn't seem to make sense. I have an Object
reference to a System.Windows.Forms.ToolStripComboBox Object that gets
initialized and performs just fine. Now, when closing the app, this
object gets Disposed. I'm trying to check whether this object is null
(Nothing, I presume) before calling one of its Properties. It seems
pretty simple, but the test for Nothing always fails claiming it's not
Nothing. Then trying to access one of its Properties results in an
NullReferenceException ;( Am I checking whether my reference Object is
null correctly?

Example:
' global scope
Dim cB As ToolStripComboBox
..
..
' Initialization and other good stuff
..
..
' Futhur down in its own Sub
..
If Not cB Is Nothing
cB.SelectedIndex = 1
End If



What we are not seeing is how the cB variable is set. You have a declaration and then a test. Nothing to set the value or to clear it that we can see.


LS

.



Relevant Pages

  • Re: Beginner level VB.NET question
    ... were a C# programmer. ... object to nothing somewhere in the code, but not realizing it is the same ... NullReferenceException;(Am I checking whether my reference Object is ... ' Initialization and other good stuff ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Beginner level VB.NET question
    ... were a C# programmer. ... object to nothing somewhere in the code, but not realizing it is the same ... NullReferenceException;(Am I checking whether my reference Object is ... many of its Properties set during the Form's Initialization process. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Contructing a dir. tree
    ... Perl programmer to think that variables must be initialized, ... The reason I set it to zero is for the same reason I set ... Again, while *you* may know the initialization is not needed, a novice ... he could be printing the Gutenberg Bible for every directory level. ...
    (comp.lang.perl.misc)
  • Re: How do I delete a folder through code?
    ... programmer assigned to the first member. ... initialized static duration data was stored in the DATA segment, ... the initialization data and copy it to these objects. ... This is an idiomatic way to initialize a data structure whose first member ...
    (microsoft.public.vc.mfc)
  • Re: automatic variables are not initialized correctly?
    ... Fortran ALLOCATABLE in COMMON. ... F77 did not have initialization statements, so it was less confusing there. ... out of context, then it is not clear whether that initialization is done once with an implied SAVE, or whether it is done repeatedly every time the subprogram in invoked. ... fortran, then you might be able to deduce what is most likely, but I think that is asking too much of a programmer, especially a modern programmer who must use several languages and where different languages treat this situation differently. ...
    (comp.lang.fortran)