Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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).

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft