Dela via


Declaration Syntax for Visual Basic 6.0 Users

Visual Basic 2008 introduces several changes related to the declaration of programming elements.

Multiple Variable Declaration

Visual Basic 2008 revises simultaneous declaration of several variables for simplification.

Visual Basic 6.0

In Visual Basic 6.0, you can declare variables of different types in the same statement, but you must specify the data type of each variable or it defaults to Variant. The following example shows multiple declarations and their resulting data types:

Dim I, J As Integer             ' I is Variant, J is Integer. 
Dim L As Integer, M As Integer  ' L is Integer, M is Integer. 
Dim N As Integer, X As Double   ' N is Integer, X is Double. 

Visual Basic

In Visual Basic 2008, you can declare multiple variables of the same data type without having to repeat the type keyword. The declarations equivalent to those in the preceding example are as follows:

Dim I                           ' I is Object. 
Dim J AsInteger                ' J is Integer. 

Or

Dim I AsObject, J AsInteger   ' I is Object, J is Integer. 
Dim L, M AsInteger             ' L is Integer, M is Integer. 
Dim N AsInteger, X AsDouble   ' N is Integer, X is Double. 

External Procedure Declaration

Visual Basic 6.0

In Visual Basic 6.0, when you declare a reference to an external procedure with the Declare statement, you can specify As Any for the data type of any of the arguments and the return type. The As Any keywords disable type checking and allow any data type to be passed in or returned.

Visual Basic

Visual Basic 2008 does not support the Any keyword. In a Declare statement, you must specifically declare the data type of every argument and the return if Option Strict is On. This improves type safety. You can overload your procedure declaration to accommodate various argument data types. You cannot overload only on return types, but you can use the argument type overloads to vary the return type, or you can turn Option Strict Off.

Line Label Declaration

Visual Basic 6.0

In Visual Basic 6.0, a line number can directly precede a statement on the same line, without any separating character.

Visual Basic

Visual Basic 2008 requires that every line label be followed by a colon (:). A statement can optionally follow the colon on the same line, or the line label and colon can stand alone on the line.

See Also

Concepts

Universal Data Type Changes for Visual Basic 6.0 Users

Procedure Calling Sequence for Visual Basic 6.0 Users

Data Types in Visual Basic

Programming Element Support Changes Summary

Reference

Declare Statement

Option Strict Statement