Assignment statements
An assignment statement evaluates an expression, and then assign the result to a variable.
Syntax
variable = expression
Set objectvar = objectexpression
Arguments
variable
A variable or a writeable property on an object.
expression
Any expression that can be evaluated to return a result.
objectvar
A variable that will be assigned a reference to the object.
objectexpression
An expression that returns an object.
Remarks
The variable used in the assignment statement must be writable at run time. For example, constants cannot be reassigned in assignment statements.
The assignment statement is used for assigning all variable types including objects.
The Set keyword, which is required in VBScript for assigning objects, is also required in mrScriptBasic for assigning objects. The Set keyword makes it possible to distinguish between object assignment and default property value assignment.
Examples
Simple variable assignment
This example assigns the sum of two variables (SpontBrands and PromptBrands) to the TotalBrands variable:
TotalBrands = SpontBrands + PromptBrands
Object assignment
This example assigns the Validation object on Q1 to the Validation object on Q2:
Set Q2.Validation = Q1.Validation
If you omit the Set keyword, the default property of the Validation object is assigned:
Q2.Validation = Q1.Validation
Object assignment using the CreateObject function
You can use the
CreateObject function to create the object. This example creates an instance of an Excel Application object:
Set xlApp = CreateObject("Excel.Application")
See also