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.
LOF Function Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses LOF to determine the length of a message which is to be
' encrypted and then decrypted.
 
' 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
 
 CLS                                     ' Clear the screen
 DIM C AS STRING * 1
 OPEN "MESSAGE.DAT" FOR OUTPUT AS #1     ' Open a text file and put
 CLS                                     ' the message "Hi there" in it
 INPUT "Enter a message for encryption: ", message$
 PRINT #1, message$
 CLOSE #1
 CLS
 PRINT "Encrypting MESSAGE.DAT"
 PRINT "   ";
 OPEN "MESSAGE.DAT" FOR BINARY AS #1     ' Encrypt the text contained within
 FOR i% = 1 TO LOF(1)                    ' MESSAGE.DAT; the encryption routine
     GET #1, i%, C                       ' replaces each ASCII character with
     C = CHR$((ASC(C) + 1) MOD 256)      ' the next ASCII character, for
     PUT #1, i%, C                       ' example, A becomes B, C becomes D
     PRINT C;                            ' Print each encrypted character
 NEXT i%
 LOCATE 3, 1
 PRINT "Decrypting MESSAGE.DAT"
 PRINT "   ";
 FOR i% = 1 TO LOF(1)                    ' Decrypt the text in MESSAGE.DAT
     GET #1, i%, C
     PRINT CHR$((ASC(C) + 255) MOD 256); ' Print each decrypted character
 NEXT i%
 LOCATE 5, 1
 PRINT "File MESSAGE.DAT contains "; LOF(1); " bytes"
 CLOSE #1
 END