Assign

Assign is an instruction that allows you to perform an assignment to a variable whose name is calculated.

Syntax

Assign NAME_EXPR With VALUE_EXPR

Examples

# 5 variables AMOUNT1 to AMOUNT5 have to be assigned from values found in an array (ARRAY_AMT)Local Integer ILocal Decimal AMOUNT1, AMOUNT2, AMOUNT3, AMOUNT4, AMOUNT5For I=1 to 5Assign "AMOUNT"+num$(I) with ARRAY_AMT(I)Next I
## For a given table record, let's assign randomly values and insert several lines# Step 1 : declarationsLocal File MYTABLE [MYT]Local Integer ILocal Integer TYP(1..[G:MYT]nbzon-1)# Step 2 : Analyze types for assignmentFor I=1 to dim(TYP)TYP(I)=evalue("type([MYT]"+[G:MYT]adxfname(I)+")")# TYP=10 for strings, TYP=1,2,3,4 for the corresponding types, TYP=5 for decimals, TYP=0 otherwiseIf TYP(I)>265 : TYP(I)=0Elsif TYP(I)>10 : TYP(I)=10Elsif find(TYP(I),5,6,7) : TYP(I)=5EndifNext I# Step 3 : Create 20 random recordsTrbegin [MYT]For I=1 to 20Gosub CREATE_RANDOM_RECORDNext ICommitEnd# The sub-program that assigns random values# The random value type depends on the type computed before$CREATE_RANDOM_RECORDFor I=1 to [G:MYT]nbzon-1For J=0 to evalue("dim([MYT]"+[G:MYT]adxfname(I)+")")Case TYP(I)When 1 : Assign "[MYT]"+[G:MYT]adxfname(I)+"("+num$(J)+")" With int(rnd(255))When 2 : Assign "[MYT]"+[G:MYT]adxfname(I)+"("+num$(J)+")" With int(rnd(32767))When 3 : Assign "[MYT]"+[G:MYT]adxfname(I)+"("+num$(J)+")" With [1/1/1970]+int(rnd(36500))When 4 : Assign "[MYT]"+[G:MYT]adxfname(I)+"("+num$(J)+")" With int(rnd(2^31-1))when 5 : Assign "[MYT]"+[G:MYT]adxfname(I)+"("+num$(J)+")" With rnd(10^10)when 10: Assign "[MYT]"+[G:MYT]adxfname(I)+"("+num$(J)+")" With sigma(1,int(rnd(20)),chr$(65+int(rnd(26))))EndcaseNext jNext IWrite [MYT]Return

Comments

The type of assignment value must be consistent with that of the variable to be assigned.

The variable to be assigned must exist.

The assign instruction does not assign a group of variables (for example, the assignment type from class to class).

See also

evalue.