Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DAY 020: MOD
#6
Since I mentioned the use of MOD and files, I might as well toss up an example.

Say we have a file called: "Great-Programs-By-Steve.dat" It's a sequential file made up of the name of the app, the creation date, the file size, and a brief description. so...

Record 1) Program Name
Record 2) Date of Creation
Record 3) File Size
Record 4) Program Description

So let's say all we want is a list of program descriptions.

OPEN "Great-Programs-By-Steve.dat" FOR BINARY AS #1

What? LOF(1) = 0. Well son of a beach!

Okay, Let's change that to "Great-Programs-By-Pete.dat" and make sure we use variable type _INTEGER64 to handle the necessary file size. Big Grin

So...

Code: (Select All)
DIM i AS _INTEGER64
IF _FILEEXISTS("Great-Programs-By-Pete.dat") THEN
    OPEN "Great-Programs-By-Pete.dat" FOR BINARY AS #1
    IF LOF(1) THEN ' Prevents an error if this is an empty file like Steves!
        DO UNTIL EOF(1)
            i = i + 1
            LINE INPUT #1, a$
            IF i MOD 4 = 0 THEN PRINT a$ ' This will print every 4th record to our screen.
        LOOP
    END IF
    CLOSE #1
END IF

Now bugger we have to remember if we want the 4th record of a 4 entry per subject file, you use equals zero instead of equals 4; but hey, that's the way MOD is meant to be used because dammit Jim, it's a math calc, not a tracking cookie.

Of course = 1, = 2, or =3 could be used to find the 1st, 2nd, or 3rd records, in our file, respectively. It's just anytime the it's the last record in the series, in this case 4th of 4, we have to remember to use = 0.

Now get ready for the KEYWORD for tomorrow, POKE; where once again it will be time to POKE fun at Steve! Big Grin

Pete
Reply


Messages In This Thread
DAY 020: MOD - by SMcNeill - 11-28-2022, 02:00 AM
RE: DAY 020: MOD - by mnrvovrfc - 11-28-2022, 02:28 AM
RE: DAY 020: MOD - by TerryRitchie - 11-28-2022, 02:32 AM
RE: DAY 020: MOD - by bplus - 11-28-2022, 02:46 AM
RE: DAY 020: MOD - by Pete - 11-28-2022, 03:31 AM
RE: DAY 020: MOD - by Pete - 11-28-2022, 04:11 AM
RE: DAY 020: MOD - by vince - 11-28-2022, 01:45 PM
RE: DAY 020: MOD - by OldMoses - 11-28-2022, 08:36 PM



Users browsing this thread: 2 Guest(s)