| Previous | Contents | Index | 
      -1 0 123 123  | 
Data types specified in a DECLARE statement override any defaults specified in COMPILE command qualifiers or OPTION statements.  | 
  
      !DEF Functions DECLARE INTEGER FUNCTION amount(,,DOUBLE,BYTE,,)  | 
      !Named Constants DECLARE DOUBLE CONSTANT interest_rate = 15.22  | 
The DEF statement lets you define a single-line or multiline function.
      !Single-Line DEF DEF DOUBLE add (DOUBLE A, B, SINGLE C, D, E) = A + B + C + D + E INPUT 'Enter five numbers to be added';V,W,X,Y,Z PRINT 'The sum is';ADD(V,W,X,Y,Z)  | 
Output
      Enter five numbers to be added? 1,2,3,4,5 The sum is 15  | 
      
PROGRAM I_want_a_raise 
 
        OPTION TYPE = EXPLICIT,                                    & 
               CONSTANT TYPE = DECIMAL,                            & 
               SIZE = DECIMAL (6,2) 
 
        DECLARE DECIMAL CONSTANT Overtime_factor = 0.50 
        DECLARE DECIMAL My_hours, My_rate, Overtime 
        DECLARE DECIMAL FUNCTION Calculate_pay (DECIMAL,DECIMAL) 
 
        INPUT "Your hours this week";My_hours 
        INPUT "Your hourly rate";My_rate 
 
        PRINT "My pay this week is"; Calculate_pay ( My_hours, My_rate ) 
 
        DEF DECIMAL Calculate_pay (DECIMAL Hours, Rate) 
 
           IF Hours = 0.0 
           THEN 
                EXIT DEF 0.0 
           END IF 
 
           Overtime = Hours - 40.0 
 
           IF Overtime < 0.0 
           THEN 
                Overtime = 0.0 
           END IF 
 
       END DEF  (Hours * Rate) + (Overtime * (Overtime_factor * Rate) ) 
 
END PROGRAM 
 | 
Output
      Your hours this week? 45.7 Your pay rate? 20.35 Your pay for the week is 987.95  | 
The DEF* statement lets you define a single- or multiline function.
The DEF* statement is not recommended for new program development. It is recommended that you use the DEF statement for defining single- and multiline functions.  | 
  
      !Single-Line DEF* DEF* STRING CONCAT(STRING A,B) = A + B DECLARE STRING word1,word2 INPUT "Enter two words";word1,word2 PRINT CONCAT (word1,word2)  | 
Output
      Enter two words? TO ? DAY TODAY  | 
      
!multiline DEF* 
DEF* DOUBLE example(DOUBLE A, B, SINGLE C, D, E) 
     EXIT DEF IF B = 0 
     example = (A/B) + C - (D*E) 
END DEF 
INPUT "Enter 5 numbers";V,W,X,Y,Z 
PRINT example(V,W,X,Y,Z) 
 | 
Output
      Enter 5 numbers? 2,4,6,8,1 -1.5  | 
The DELETE statement removes a record from a relative or indexed file.
Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#).
      
DECLARE STRING record_num 
   .
   .
   .
OPEN "CUS.DAT" FOR INPUT AS #1, RELATIVE FIXED       & 
      ACCESS MODIFY, RECORDSIZE 40 
   .
   .
   .
INPUT "WHICH RECORD WOULD YOU LIKE TO EXAMINE";record_num 
GET #1, RECORD record_num 
DELETE #1 
   .
   .
   .
 | 
In this example, the file CUS.DAT is opened for input with ACCESS MODIFY. Once you enter the number of the record you want to retrieve and the GET statement executes successfully, the current record number is deleted.
The DET function returns the value of the determinant of the last matrix inverted with the MAT INV function.
None
      MAT INPUT first_array(3,3) MAT PRINT first_array; PRINT MAT inv_array = INV (first_array) determinant = DET MAT PRINT inv_array; PRINT PRINT determinant PRINT MAT mult_array = first_array * inv_array MAT PRINT mult_array;  | 
Output
      ? 1,0,0,0,1,0,0,0,1 1 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 1  | 
The DIF$ function returns a numeric string whose value is the difference between two numeric strings.
Each str-exp can contain up to 60 ASCII digits, an optional decimal point, and an optional leading sign.
      
PRINT DIF$ ("689","-231") 
 | 
Output
      920  | 
| Previous | Next | Contents | Index |