ex.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.
CVx and MKx$ Functions Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses the MKS$ and CVS functions to convert values to and from
' strings for storage in a random-access file.
 
' Note: If you run this program, you will be prompted to enter an account
' number. The account numbers in the sample data file ACCOUNT.INF are 1 - 5.
 
' To try this example:
' 1. Choose New project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 TYPE Buffer                    ' Define a user type for the data records
     AccName AS STRING * 25
     Check   AS STRING * 4
 END TYPE
 
 DIM BankBuffer AS Buffer       ' Define a variable of the variable type
 
 CLS                            ' Clear the screen
 OPEN "ACCOUNT.INF" FOR RANDOM AS #1 LEN = 29
 CLS
 RESTORE
 READ AccName$, Check
 I% = 0
 DO WHILE UCASE$(AccName$) <> "END"
     I% = I% + 1
     BankBuffer.AccName = AccName$
     BankBuffer.Check = MKS$(Check)
     PUT #1, I%, BankBuffer
     READ AccName$, Check$
     IF AccName$ = "END" THEN EXIT DO
 LOOP
 CLOSE #1
 
 DATA "Bob Hartzell", 300
 DATA "Alice Provan", 150
 DATA "Alex Landow", 75
 DATA "Walt Riley", 50
 DATA "Georgette Gump", 25
 DATA "END", 0
 
 OPEN "ACCOUNT.INF" FOR RANDOM AS #2 LEN = 29
 FIELD #2, 25 AS AccName$, 4 AS Check$
 DollarFormat$ = "$$#####.##"
 DO
     PRINT
     DO
          CLS                     ' Clear the screen
          INPUT "Enter account # to update: ", Rec%
          GET #2, Rec%            ' Get the record
          PRINT : PRINT "This is the account for "; AccName$
          PRINT : INPUT "Is this the account you wanted"; R$
     LOOP WHILE UCASE$(MID$(R$, 1, 1)) <> "Y"
     Checkamt! = CVS(Check$)      ' Convert string to single-precision value
     PRINT
     PRINT "The opening balance for this account is";
     PRINT USING DollarFormat$; Checkamt!
     PRINT : PRINT "Enter the checks and cash withdrawals for this"
     PRINT "account below. Enter 0 when finished."
     PRINT
     DO
          INPUT "Enter amount -> ", Checkout!
          Checkamt! = Checkamt! - Checkout!
     LOOP UNTIL Checkout! = 0
     PRINT
     PRINT "Enter the deposits for this account below."
     PRINT "Enter 0 when finished."
     PRINT
     DO
          INPUT "Enter amount ->", Checkin!: Checkamt! = Checkamt! + Checkin!
     LOOP UNTIL Checkin! = 0
     PRINT
     PRINT "The closing balance for this account is";
     PRINT USING DollarFormat$; Checkamt!
     LSET Check$ = MKS$(Checkamt!)' Convert single-precision number to string
     PUT #2, Rec%                 ' Store the record
     PRINT : INPUT "Update another"; R$
  LOOP UNTIL UCASE$(MID$(R$, 1, 1)) <> "Y"
  CLOSE #2
  KILL "ACCOUNT.INF"
  END