ASSIGNED()

ASSIGNED()

Top  Previous  Next

 

The ASSIGNED() function tests whether a variable is assigned.

 

 

Format

 

ASSIGNED(var)

 

where

 

varis the variable to be tested.

 

 

All QMBasic variables except those in common blocks are initially unassigned. Any attempt to use the contents of the variable in an expression would cause a run time error until such time as a value has been stored in it. The ASSIGNED() function allows a program to test whether a variable has been assigned, returning True if it is assigned or False if it is unassigned.

 

 

Example

 

SUBROUTINE VALIDATE(ACCOUNT.CODE, ERROR)

  IF ASSIGNED(ACCOUNT.CODE) THEN

     ERROR = 0

     …processing code…

  END ELSE

     ERROR = 1

  END

  RETURN

END

 

This program fragment validates an account code. The use of the ASSIGNED() function prevents an abort if the variable has not been assigned.

 

 

See also:

UNASSIGNED()