Table of contents
TOC
Collapse the table of content
Expand the table of content

Let Statement

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Assigns the value of an expression to avariable orproperty.

Syntax

[ Let ] varname=expression

The Let statement syntax has these parts:

PartDescription
LetOptional. Explicit use of the Letkeyword is a matter of style, but it is usually omitted.
varnameRequired. Name of the variable or property; follows standard variable naming conventions.
expressionRequired. Value assigned to the variable or property.

Remarks A value expression can be assigned to a variable or property only if it is of a data type that is compatible with the variable. You can't assignstring expressions to numeric variables, and you can't assignnumeric expressions to string variables. If you do, an error occurs atcompile time. Variant variables can be assigned either string or numeric expressions. However, the reverse is not always true. Any Variant except aNull can be assigned to a string variable, but only a Variant whose value can be interpreted as a number can be assigned to a numeric variable. Use the IsNumeric function to determine if the Variant can be converted to a number. Assigning an expression of one numeric type to a variable of a different numeric type coerces the value of the expression into the numeric type of the resulting variable. Let statements can be used to assign one record variable to another only when both variables are of the sameuser-defined type. Use the LSet statement to assign record variables of different user-defined types. Use the Set statement to assign object references to variables.

Example

This example assigns the values of expressions to variables using the explicit Let statement.

Dim MyStr, MyInt 
' The following variable assignments use the Let statement. 
Let MyStr = "Hello World" 
Let MyInt = 5 

The following are the same assignments without the Let statement.

Dim MyStr, MyInt 
MyStr = "Hello World" 
MyInt = 5 
© 2017 Microsoft