bas7ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
DIM Statement Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses the DIM statement to set the dimensions for an array.
'The program finds and prints the maximum and minimum of a set of values.
 
'Dimension an array to hold the values.
CONST MAXDIM=20
DIM A(1 TO MAXDIM)
'Use DIM to set up two integer variables.
'All other variables are single-precision.
DIM NumValues AS INTEGER, I AS INTEGER
 
'Get the values.
NumValues=0
PRINT "Enter values one per line. Type END to end."
DO
   INPUT A$
   IF UCASE$(A$)="END" OR NumValues>=MAXDIM THEN EXIT DO
   NumValues=NumValues+1
   A(NumValues)=VAL(A$)
LOOP
 
'Find the maximum and minimum values.
IF NumValues>0 THEN
   Max=A(1)
   Min=A(1)
   FOR I=1 TO NumValues
      IF A(I)>Max THEN Max=A(I)
      IF A(I)<Min THEN Min=A(I)
   NEXT I
 
   PRINT "The maximum is ";Max;" The minimum is ";Min
ELSE
   PRINT "Too few values."
END IF
 
'Sample Output
'
'Enter values one per line. Type END to end.
'? 23.2
'? 11.3
'? 1.6
'? end
'The maximum is  23.2  The minimum is  1.6