Assignment Statement

Assigns a value to a variable.

Syntax

lvalue = expression

Comments

The lvalue expression on the left hand side of the assignment statement must be a property or a variables. A variable can be a non-array variable (x), an element of an array (ax[i,j,k]), a structure field (struct1.field7), or an object property (Form.Caption). The term l-value is often used as shorthand for all of the above possibilities, that is, something which can be on the left side of an assignment statement. The left hand side must not have the Const property or be a read-only property of an object.

A variable of any simple data type can be assigned to another variable of the same data-type. Two structure variables are assignment compatible if they have the same structure type. Two arrays are assignment compatible it they have the same data type, the same number of dimensions, and the same size for each dimension.

If the data type of the right hand side differs from that of the left hand side, it must be possible to convert the right hand side to the type of the left. See the Data Conversion topic for a description of data types that can be converted. For example, any numeric data type can be converted to any other numeric data type, and each of the two string types can be converted to the other.

In ATEasy 5, ATEasy allows character data conversion; that is, a byte or char array can assign to String or vise versa.

In ATEasy 5, ATEasy allows a Procedure variable to be assign to String or Variant (string type) and vice versa. Also ATEasy allows comparison between procedure and string. See below for examples.

Also ATEasy allows a variable of type Currency or DateTime to be set to a string and vice versa. Thus, you can set the initial value of variables of Currency or DateTime type from a string ("$30,000" or "9/21/2007 9:11 AM") and also set to the variable to a string.  See below for examples.

Example

i = 1

s = s+"ABCD"

as[i] = Form.Caption ! assign BString to String

af[i, j] = fX*PI+1

dHeight = 5 ! assign long to double

! the following assignment statements will result in a parse error

s = 9 ! can't convert a long to a string

2 = 3 ! can't assign to a literal constant

sin(x) = 0 ! can't assign to a function value

 

! character data conversion - say aCharArray is an array of characters of size 10  (ATEasy 5)

sString="test string"

aCharArray=sString!aCharArray contains "test strin"-10 characters copied

 

! assign String to Proc, a variable of type Procedure, type and vice versa  (ATEasy 5)

! (1) string to proc

if iProc=0

procDisplay="DisplayCustomTestType1"

else

procDisplay="DisplayCustomTestType2"

endif

procDisplay(TestResult)

!(2) array of Procedures, aprocDisplay[]

for i=0 to iSize do

s="DisplayCustomTestType"+Str(i+1)

aprocDisplay[i]=s

next

! (3) proc to string/variant string type and their comparison

proc="Language.Average"! proc is a variable of type "Procedure"

sProc=proc             ! assign proc to a string    

print sProc            ! this prints  "Language.Average"

if proc=sProc          ! compare proc to string   

print "True"        ! this will print

else

print "False"

endif

vr=sProc               ! this makes variant of string type

print vr               ! this prints "Language.Average"

if proc=vr             ! this comparison results True

print "True"

else

print "False"

endif

 

!(4) Currency to String type and vice versa

curTotalSales="$300,000.00"

sTotalSales=curTotalSalea

 

!(5) DateTime to String type and vice versa

dtmToday="9/21/2007 9:50:00 AM"

sCurrentDate=dtmToday

See Also

Data Conversion, Expressions, MemoryCopy