Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual Basic
 Variable '<variablename>' is used b...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Basic Reference: Error Messages
Variable '<variablename>' is used before it has been assigned a value

Error Message

Variable '<variablename>' is used before it has been assigned a value. A null reference exception could result at run time.

An application has at least one possible path through its code that reads a variable before any value is assigned to it.

If a variable has never been assigned a value, it holds the default value for its data type. For a reference data type, that default value is Nothing (Visual Basic). Reading a reference variable that has a value of Nothing can cause a NullReferenceException in some circumstances.

By default, this message is a warning. For more information on hiding warnings or treating warnings as errors, see Configuring Warnings in Visual Basic.

Error ID: BC42104

To correct this error

  • Check your control flow logic and make sure the variable has a valid value before control passes to any statement that reads it.

  • One way to guarantee that the variable always has a valid value is to initialize it as part of its declaration. See "Initialization" in Dim Statement (Visual Basic).

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker