Several tags use the 'type' attribute to define the expected data type of an item (i.e. the type of value stored in a variable or returned from a function). VBScript is not a strongly-typed language. This means that you do not have to explicitly define the data types in use. Even though data types do not have to be defined, it is useful to know the type of value that is expected, and often considered bad programming practice to vary the content that is stored in a single variable.
For example, knowing that a parameter to a function takes a Boolean value instead of a String value help indicate the type of data you need to pass to the function.
The 'type' attribute is used by XML Comments to optionally provide this level of detail. When the type is defined, it will appear in the Object Browser, IntelliSense, and Documentation.
Typical types for VBScript include:
In addition to the standard type values, you use the name of an enum (built-in or user-defined) as a data type. This links an item to a specific list of values.
Several built-in enums exist for VBScript as well as some specific lists for Unified Functional Testing. The enum 'Comparison', for instance, groups the pre-defined constants that are used to specify how
two string values are compared in VBScript functions like 'StrComp' (i.e. case-sensitive or case-insensitive). If you were to create your own functions that involved string-based comparisons, you might
want to use the same values as the 'StrComp' function. While these constants are technically of the data type
Integer, it would be more specific to indicate they are values from the 'Comparison' enum.
The following example illustrates a function declaration that expects one
Integer parameter from the enum 'Comparison'.
''' <param name="Param1" type="Comparison"/> Public Function TestFunction(ByVal Param1) End Function
Tip: When you specify an enum as the data type for the parameter to a function, an IntelliSense Member List of values from that enum will be displayed while typing the parameter details of a function call.
When an item will hold a specific type of object, it is ideal to use the 'type' attribute to specify the class name of the object. This will enable IntelliSense to be able to display the members of that object class. Having this IntelliSense available can greatly reducing typing errors and eliminate the need to refer back to documentation. This technique works with VBScript classes as well as classes from COM libraries. Simply enter the name of the class for the 'type' attribute. The following example illustrates a variable that holds a reference to a user-defined VBScript class.
Class TestClass Public Function TestFunction End Function Public Property Get TestProperty End Property End Class ''' <value type="TestClass"/> Dim x
x holds a reference to the 'TestClass' class. While typing in the editor, if you type
x., the IntelliPrompt member list will automatically be shown based on the members
of the class 'TestClass'.
This concept can also be applied to properties of classes when a property returns an instance of a class. The following example illustrates how to indicate that a property returns a particular type of class.
Class TestClass Public Function TestFunction End Function ''' <value type="ClassFromProperty"/> Public Property Get TestProperty End Property End Class Class ClassFromProperty Public Function MyFunction End Function End Class ''' <value type="TestClass"/> Dim x
x still holds a reference to the 'TestClass' class like the previous example and is used to access the 'TestProperty' member of that class. While typing in the editor, if you type
x.TestProperty., the IntelliPrompt member list will automatically be shown based on the members
of the class 'ClassFromProperty'.
Scripting.FileSystemObjectto refer to the "FileSystemObject" class from the "Microsoft Scripting Runtime" COM Library.
''' <value type="Scripting.FileSystemObject"/> Dim fso
You do not have to use the 'type' attribute for a COM object that is instantiated by using the VBScript 'CreateObject' function. In the following example, the variable
fso will automatically
be associated with the type "Scripting.FileSystemObject".
Dim fso Set fso = CreateObject("Scripting.FileSystemObject")
Tip: Use of the 'Dim' statement is optional in the context of the 'CreateObject' function.