ASSIGN

Contents


Assign assigns a variable for which you do not know the name beforehand.

 

Syntax

Assign name_exp With value_exp

 

Parameters

Element

Description

Restrictions

name_exp

Expression of the Char type which results in the name of a variable

The variable must exist.

value_exp

Any expression

Its type must be compatible with that of the variable.

 

Examples

# Loading of the REP1 and REP2 fields of the current line of the table of the SDH1 screen with the value of the REP(0) and REP(1) fields of the SDH2 screen.
For I=0 To 1
   Assign ("[M:SDH1]REP"+num$(I+1)+"(nolign-1)")
      With evalue("[M:SDH2]REP("+num$(I)+")")
Next

# Displaying Program: I=3
Default Local
Char NOM(10): Description I
[L]NOM = "[L]I"
Assign [L]NOM With 3
Infbox "I="-[L]I

# Load 1000 records in the FILE table
# with values calculated randomly

Local Char NOM_FIC(10)
[L]NOM_FIC = "FILE"
If filinfo(filpath("FIL",[L]NOM_FIC,"srf"),1) >= 0
Call FILL([L]NOM_FIC)
Endif
End

Subprog FILL(NOMFIC)
Value Char NOMFIC()
Local File =NOMFIC [XX]
Local Shortint TYP

## Loop on the number of records to be written
For I=0 To 999
## Loop on the number of fields of the file
For J=0 To [G:XX]nbzon-1
## Loop on the dimension of each field
For K=0 To evalue("dim([F:XX]"+[G:XX]adxfname(J)+")-1")
## Description(1) Shortint(2) Date(3) Integer(4)
#(continuation of the previous example)
## Decimal(7,9) Char(>10)

[L]TYP = evalue("type([F:XX]"+[G:XX]adxfname(J)+")")
Case [L]TYP
When 1:
Assign[G:XX]adxfname(J)+"(K)" With int(rnd(255))
When 2:
Assign[G:XX]adxfname(J)+"(K)" With int(rnd(32768))
When 3:
Assign[G:XX]adxfname(J)+"(K)" With date$+int(rnd(365))
When 4:
Assign[G:XX]adxfname(J)+"(K)" With int(rnd(2^31-1))
When 7:
Assign[G:XX]adxfname(J)+"(K)" With rnd(10^79)
When Default
Assign[G:XX]adxfname(J)+"(K)" With
& sigma(L=0, [L]TYP-10-1, chr$(int(rnd(25)+ascii('A'))))
Endcase
Next K
Next J
Write [XX]
Next I
End

 

Description and Comments

"assign" assigns a variable (declared beforehand) for which you do not know the name at the time of the assignment. In order to do this, an alphanumeric variable with the variable name to be assigned as a value is required.

The "known" variable name is to be given as the first parameter of the "assign" instruction.

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

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

 

Associated Errors

Error

Description

ERMODE (10)

Alphanumeric Incompatibility

ERVARI ( 6)

Variable does not exist.

ERCLAS ( 7)

Class does not exist.

ERINDI (8)

Index invalid

ERHUGE (13)

Numeric capacity exceeded

 

Associated Keywords

CHAR - SHORTINT - INTEGER - DATE - LIBELLE - DECIMAL - TYPE - DIM


CONTENTS


Copyright © Sage 1999 - 2007