LET statement  


Assign a value to a variable.


[LET] variable  = expression
[LET] variable += expression
[LET] variable -= expression
[LET] variable *= expression
[LET] variable /= expression
[LET] variable \= expression
[LET] variable &= expression
LET] variable AND= expression
[LET] variable OR= expression
[LET] variable EQV= expression
[LET] variable IMP= expression
[LET] variable MOD= expression
[LET] variable XOR= expression


Simple assignment

variable is a string or numeric variable, and expression is of a suitable type (that is, a string expression for string variables and numeric expression for numeric variables).

The word LET is optional in assignment statements.  It is allowed to provide compatibility BASIC source files written for early versions of BASIC.  In practice, the word LET is very rarely used.

To allow easy conversion, PowerBASIC allows a User-Defined Type in a string expression.  The User-Defined Type is simply copied, byte for byte, into the expression.  However, to assign a string back to a User-Defined Type, you should use the TYPE SET statement.

DIM abc as MyType
MyString$ = abc

Please refer to the following sections of the LET statement for special information regarding assignment using Object variables, Variant variables, and User-Defined Type variables.

Compound assignment

A compound assignment statement combines a binary arithmetic operator, a binary bitwise operator, or a binary string operator (concatenation) as an integral part of the assignment.  This offers the programmer a "shortcut" in your source code, and can even result in more efficient code generation.  That's because the target variable is evaluated only once, even if an array or pointer calculation could have a side effect which changes it.

Compound assignments are available for the standard arithmetic operations of add, subtract, multiply, divide, int-divide, and modulo (+ - * / \ MOD), the bitwise operations (AND, OR, XOR, EQV, IMP), and the concatenation operators (+ &).  Each are represented by one of the following tokens:













Each of the following pairs of code are functionally identical:

x = x + 1

x += 1

x = x / y

x /= y

x = x XOR 3

x XOR= 3

x(7) = x(7) AND 5

x(7) AND= 5

x$ = x$ + y$

x$ += y$

See also

BUILD$, JOIN$, LET (with Objects), LET (with Variants), LET (with Types), TYPE SET


MyString$ = "This is a test."
LET TempStr$ = MyString$
LET MyVarr -= YourVar