| .CVI Function Programming Example. |
|
  QuickSCREEN       Details      Example       Contents       Index |
| ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ |
| CVI, CVS, CVL, and CVD Functions Programming Example |
|
| The following program illustrates the use of MKS$ and CVS. If you run |
| this program, you will be prompted to enter an "account #." The account |
| numbers in the sample data file ACCOUNT.INF are 1, 2, 3, 4, and 5. |
|   |
| After you enter an account number, the program gives you a chance to |
| update the account balance. |
|   |
| ' *** Example program that uses the CVS function *** |
| ' |
| ' Define a user type for the data records. |
| TYPE Buffer |
|    AccName AS STRING * 25 |
|    Check   AS STRING * 4 |
| END TYPE |
| ' Define a variable of the variable type |
| DIM BankBuffer AS Buffer |
| 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$ |
|   |
| Format$ = "$$#####.##" |
| DO |
|    PRINT |
|    DO |
|       INPUT "Enter account # to update: ", Rec% |
|       GET #2, Rec%                               'Get the record |
|       PRINT "This is the account for "; AccName$ |
|       INPUT "Is this the account you wanted"; R$ |
|    LOOP WHILE UCASE$(MID$(R$, 1, 1)) <> "Y" |
|   |
|    'Convert string to single-precision number. |
|    Checkamt! = CVS(Check$) |
|    PRINT |
|    PRINT "The opening balance for this account is"; |
|    PRINT USING Format$; Checkamt! |
|    PRINT "Enter the checks and cash withdrawals for this" |
|    PRINT "account below. Enter 0 when finished." |
|   |
|    DO |
|       INPUT Checkout! |
|       Checkamt! = Checkamt! - Checkout! |
|    LOOP UNTIL Checkout! = 0 |
|   |
|    PRINT |
|    PRINT "Enter the deposits for this account below." |
|    PRINT "Enter 0 when finished." |
|   |
|    DO |
|       INPUT Checkin!: Checkamt! = Checkamt! + Checkin! |
|    LOOP UNTIL Checkin! = 0 |
|   |
|    PRINT |
|    PRINT "The closing balance for this account is"; |
|    PRINT USING Format$; Checkamt! |
|    'Convert single-precision number to string. |
|    LSET Check$ = MKS$(Checkamt!) |
|    PUT #2, Rec%                                  'Store the record. |
|    INPUT "Update another"; R$ |
|   |
| LOOP UNTIL UCASE$(MID$(R$, 1, 1)) <> "Y" |
| CLOSE #2 |
| END |