TypeName - VBScript
TypeName
Overview
The TypeName
command in VB Script returns a string representing the VBA type of a variable, object, or expression. It is used to identify the data type of values during runtime.
Syntax
TypeName(expression)
Parameters:
expression
: Required. The variable, object, or expression to evaluate.
Options/Flags
None.
Examples
Dim myVariable As String
myVariable = "Hello"
Debug.Print TypeName(myVariable) ' Output: String
Dim myObject As New Scripting.Dictionary
TypeName(myObject) ' Output: Dictionary
Common Issues
- Ensure the expression provided is valid and does not raise errors.
- Remember that
TypeName
returns the type at runtime, which may differ from the declared type in the code.
Integration
- Use
TypeName
to dynamically check data types at runtime for data validation purposes. - Combine
TypeName
with other commands likeVarType
andIsObject
for advanced data manipulation and object detection.
Related Commands
VarType
: Returns a numeric value indicating the data type.IsObject
: Determines if an object is an instance of a class.