Expressions in Visual Basic
The Visual Studio debugger includes a Visual Basic expression evaluator that evaluates expressions that you enter in the QuickWatch dialog box, in the Watch window, or in the Autos, Local, or in the Me windows. The expression evaluator is also at work in the Breakpoints window. If you type the name of a function where you want to set a breakpoint, for example, the expression evaluator handles it.
The managed expression evaluator accepts most expressions written in Visual Basic. The following topics offer specific information and discuss some of the expression types that are not supported:
- Identifiers and Types
- Function Evaluation
- Unsupported Keywords
- TypeOf Operator
- Object Variables Containing Intrinsic Types
- Property Evaluation
- Variable Declarations
Visual Basic does not support autoexpand rules for displaying the contents of a data type in meaningful form. For more information, see Displaying Elements of a Custom Data Type.
Debugger expressions can use any identifier visible within the current scope. If the debugger is halted in function
magh, for example, you can use most identifiers visible within
magh, including variable names and function names. Local constants are not supported. You can set the value of any variable visible within the current scope.
The debugger can correctly display any variable of a primitive or intrinsic type. For variables of class type, the debugger correctly displays the value based on the derived-most type. If you have an object
leo of type
lion, derived from type
cat, you can evaluate
leo.clawlength and get the correct value for an object of type
The debugger supports the evaluation of functions, including overloaded functions. Therefore, you can enter either of the following expressions, and the debugger will call the correct version of the overloaded function:
kanga (roo) kanga (roo, stew)
Evaluating a function in the debugger actually calls and executes the code for that function. If the function has side effects, such as allocating memory or changing the value of a global variable, evaluating the function in a debugger window will change the state of your program, which can produce unexpected results.
When you set a breakpoint on an overloaded function, the location of the breakpoint depends on how you specify the function. If you specify only the function name, the debugger will set one breakpoint on each overload of that function name. If you specify the complete signature (function name and full argument list), the debugger sets one breakpoint on the specified overload.
The debugger correctly evaluates most operators, including:
- Arithmetical operators. Examples: ( expr1 + expr2, expr1 - expr2, expr1 * expr2, expr1 / expr2, expr1 \ expr2, expr1 ^ expr2 , expr1 Mod expr2 ).
- Assignment operators. Examples: ( var1 = expr2, var1 ^= expr2, var1 *= expr2, var1 /= expr2, var1 \= expr2, var1 += expr2, var1 -= expr2, var1 &= expr2 ).
- Comparison operators. Examples: ( expr1 < expr2, expr1 <= expr2, expr1 > expr2, expr1 >= expr2, expr1 = expr2, expr1 <> expr2 ).
- Concatenation operators. Examples: ( expr1 & expr2, expr1 + expr2 ).
- Logical operators. Examples: ( expr1 And expr2, expr1 Or expr2, expr1 XOr expr2, expr1 AndAlso expr2, expr1 OrElse expr2, Not expr1 ).
- Unary operators. Examples: ( -expr1, Not expr1, GetType (type) ).
The following Visual Basic keywords are not supported in debugger window expressions:
- On Error
In Visual Basic, you can use the
Length operator on a string:
Simple casts work in the debugger:
A = CStr(B)
The use of CType for casting does not work in the debugger:
A = CType(B, NewType)
In Visual Basic, you can use the TypeOf operator in the debugger windows:
TypeOf expression Is type
TypeOf Me Is Integer
displays the value false.
If you use TypeOf, it must part of an expression that uses Is. If you use TypeOf without Is, you will get the following error message:
Object variables that contain intrinsic variable types, such as integer, are displayed and edited in a manner that may appear unintuitive. For example, suppose you have an object variable like this:
Dim o As Object = 5
The debugger displays the value of this variable as:
To change the value of this variable to 6, you would enter:
You would not enter:
- You cannot use import aliases in the debugger windows.
The debugger can evaluate properties in any variable window. However, evaluating a property in the debugger can have side effects (such as changing variable values) that affect program results. To protect against side effects caused by accidental evaluation, you can turn property evaluation off in the General, Debugging, Options dialog box.
You cannot call WebMethods from debugger windows.
You cannot declare new variables in debugger windows.