Operands of type Object used in expressions for 'Select', 'Case' statements; runtime errors could occur

A Select...Case construction uses one or more expressions of the Object Data Type.

When a variable or expression evaluates to Object, the compiler must perform late binding, which causes extra operations at run time. It also exposes your application to potential run-time errors. For example, if you assign a Form to an Object variable and then try to compare it with a number, the runtime throws an InvalidCastException because Visual Basic cannot convert a Form object to a numeric value.

The expressions in a Select...Case construction should all be of the same data type or of closely related data types that can be converted to each other. This is because each Case statement compares at least one value against the test expression on which the Select...Case construction is based.

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

Error ID: BC42036

To correct this error

  • If possible, arrange all the expressions to evaluate to data types for which comparison operators are defined.

See Also

Concepts

Arithmetic Operators in Visual Basic

Comparison Operators in Visual Basic

Reference

Select...Case Statement (Visual Basic)