HTBasic Help
×
Menu
Index

Using Array Variables

 

Introduction

As you add attributes to a DIALOG statement, the line may get too long and may become difficult to read. Since a DIALOG statement must fit in one line, it is good practice to use array variables to set dialog attributes.
 

Placing Attribute Values in String Arrays

In general, you can put all attributes that require a numeric value into one string array, and then invoke them along with a matching numeric array. For example:
 
DATA "ATTRIBUTE 1","ATTRIBUTE 2","ATTRIBUTE 3","ATTRIBUTE 4","ATTRIBUTE 5"
READ An$(*)
DATA 12,32,100,6,19
READ Vn(*)
...
DIALOG Type$,Prompt$,Btn;SET (An$(*):Vn(*))
 
You could also make another set of arrays for the attributes that required string values, say As$(*) and Vs$(*), but mixing the two types is not allowed. For example:
 
DIALOG Type$,Prompt$,Btn;SET (An$(*):Vn(*),As$(*):Vs$(*))
 

Example: Using Array Variables

For example, the ERROR dialog program can also be written as follows.
 
! Example: Using Array Variables
!
DIM T$[16],P$[40],A1$[20],S1$(1:2)[10],A2$[20]
INTEGER Btn
DATA "ERROR","Input caused overflow!"
READ T$,P$
DATA "DIALOG BUTTONS","ABORT","CONTINUE","DEFAULT BUTTON"
READ A1$,S1$(*),A2$
!
DIALOG T$,P$,Btn;SET (A1$:S1$(*),A2$:0),TIMEOUT 5
IF Btn=-1 THEN
   DISP "NO ENTRY"
ELSE
   DISP S1$(Btn + 1)
END IF
END
 
With these changes, room is provided to include a TIMEOUT. Adding TIMEOUT also required a change in the handling of the value of "Btn", since Btn returns a "-1" value if the dialog times out. String variables A1$ and A2$ are the names of two dialog attributes, and a string array S1$() is the name for the attribute values.