BC42104: Variable '<variablename>' is used before it has been assigned a value

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

See also