### Assignment operators

#### Basic syntax (x = y)

You can use the assignment operator (=) and the assignment keyword "Let" (Let x=y) with only Basic syntax. Crystal syntax uses the other assignment operator (:=).

##### Usage

`x = y`

Assigns y to the variable x. x must have already been declared before the assignment. y must be of the same type as x, or of a type compatible with x.

`Let x = y`

Assigns y to the variable x. x must have already been declared before the assignment. y must be of the same type as x, or of a type compatible with x.

##### Examples

The following example is applicable to Basic syntax:

Dim n As Number
Dim b As Boolean
Dim c As Currency
Dim d As Date
Dim t As Time
Dim s As String
Dim numArray () As Number
'n is assigned 100
n = 100
'b is assigned the Boolean value True
b = True
'c is assigned the Currency value 5000
c = CCur (5000)
'd is assigned the Date value of Oct. 10, 1999
d = CDate ("10, 10, 1999")
't is assigned the Time value 12:50am
t = CTime ("12:50am")
' s is assigned a string which is a concatenation of 2 substrings and a field value
s = "The total sales is " & {Orders.Order Amount} & " billion."
' numArray is assigned an array of Number values
numArray = Array (10, 20, 30)
formula = s

##### Comments

- A variable must be declared in a separate statement before it is assigned any value in Basic syntax.
- Assignment only assigns a value to a variable. When a formula returns, the value assigned to the variable Formula is then formatted according to the format specified for that formula field of the corresponding type.

#### Crystal syntax (x := y)

You can use the assignment operator (:=) with only Crystal syntax. For more details, see Variable declarations.

##### Usage

`x := n`

Assigns the value n to the variable x. (x must have already been declared in the same formula.)

##### Examples

The following examples are applicable to Crystal syntax:

`Amount:= 0`

Initializes (sets to zero) the variable named Amount.

`Amount:= 100`

Assigns the value 100 to the variable named Amount.

`Amount:= Amount + {file.QTY}`

Assigns the result of a calculation to the variable named Amount. The calculation adds the value of the quantity field ({file.QTY}) to the current value of the Amount variable.

`Amount:= {file.QTY1} + {file.QTY2} + {file.QTY3}`

Totals the three quantity fields and assigns the total to the variable named Amount.

`Customer:= "Westside Motors"`

Assigns the string "Westside Motors" to the variable named Customer.

`Customer:= {customer.FIRST NAME} + {customer.LAST NAME}`

concatenates two fields and assigns the concatenated value of both fields to the variable named Customer.

`Customer:= TrimRight({customer.FIRST NAME}) + {customer.LAST NAME}`

Trims the trailing blanks from the first name field ({customer.FIRST NAME}), concatenates that field to the last name field ({customer.LAST NAME}), and assigns the concatenated value of both fields to the variable named Customer.

`Customer:= "Mr. " + {customer.LAST NAME}`

Concatenates the string "Mr. " with the value of the last name field {customer.LAST NAME} and assigns the concatenated value to the variable named Customer.

`Amount:= 100; Customer:= "Westside Motors"`

Assigns the constant 100 to the number variable named Amount and assigns the string "Westside Motors" to the string variable named Customer. You can assign values to multiple variables by separating the assignment statements with semicolons.

Seagate Software, Inc. http://www.seagatesoftware.com Please send comments to: techpubs@seagatesoftware.com