saving using bload/bsave

 BBS: Inland Empire Archive
Date: 05-12-92 (10:47)             Number: 87
From: RICK PEDLEY                  Refer#: NONE
  To: CHARLIE QUANTE                Recvd: NO  
Subj: saving using bload/bsave       Conf: (2) Quik_Bas
 On 05-10-92 CHARLIE QUANTE wrote to All...

 CQ> Hello!
 CQ>
 CQ>       I posted this as part of an earlier message, and got
 CQ> no reply.  Either my message got lost in the flow, or I've
 CQ> stumped the talented programmers here.  Either way, I
 CQ> thought I would try once more.

What sometimes happens is everyone has seen this question asked many
times, so they'll sit back and wait for someone else to answer it.
Fortunately, I've saved over a year's worth of useful messages from
this echo, so it's just a matter of shelling out to LIST and searching
for the code.

 CQ>       I have a program using a 40 by 40 integer array.  It is part of a
 CQ> door
 CQ> program I wrote, and I read the array info from a
 CQ> sequential file.  It seems to take FOREVER!  I saw
 CQ> something in a book, (unfortunately I can't remember
 CQ> where), that used BLOAD and BSAVE to load and save a single
 CQ> dimension array. The address of the first array element was
 CQ> involved, as well as the total size in bytes of the array.
 CQ> Would something similar work with a two dimensional array?
 CQ> How exactly would I code that?  Is there a better, quicker
 CQ> way?

Here's a message from Matt Hart that shows how to save and load an
array.  For a two dimensional array, it's almost the same method,
but you have to calculate the number of bytes you need a little
differently.  First, be sure to specify the upper and lower bounds
in your DIM statement, e.g. DIM A%(1 TO 40, 1 TO 20), or at least
realize if you don't, you must remember to save the (0,y) & (x,0)
elements even if you don't use them for anything.  So with the
example array above, you'd need 40 * 20 * 2 bytes and if you don't
specify the lower bounds, 41 * 21 * 2 to include the zero elements.
This'll run so quickly, you'll think it didn't :)

Date: 11-19-91 (18:07)             Number: 243
From: MATT HART                    Refer#: 206
  To: MIKE AVILA                    Recvd: NO
Subj: Saving Arrays to File          Conf: (2) Quik_Bas
___---------------------------------------------------------- You can't save a string array to disk all in one shot, but you can save an integer array. REDIM StrArray$(100) OPEN "O",1,"STRFILE.DAT" WRITE #1,UBOUND(StrArray$) ' you'll need it later FOR i=1 TO UBOUND(StrArray$) WRITE #1,RTRIM$(StrArray$(i)) NEXT i CLOSE 1 To retrieve it: OPEN "I",1,"STRFILE.DAT" INPUT #1,DimSize REDIM StrArray$(DimSize) FOR i=1 TO DimSize INPUT #1,StrArray$(i) NEXT i CLOSE 1 '^^^^^ Included for completeness. Numeric array info starts here. -- R.P. For numeric arrays, you can use bsave/bload Check out OPTION BASE command to know where to start, because the first array element can be (0) or (1) or anything you specify. Normally, you dim arrays (REDIM Array%(100)), but I recommend always specifying both the upper and lower bounds, REDIM Array%(1 TO 100) NumBytes& = UBOUND(Array%) * 2 ' 4 for ! and &, 8 for # DEF SEG = VARSEG(Array%(1)) BSAVE "ARRAY.BIN",VARPTR(Array%(1)),NumBytes& DEF SEG To retrieve, you can get the size with: OPEN "R",1,"ARRAY.BIN" : DimSize = (LOF(1)-12)\2 : CLOSE 1 '\4! or 8# REDIM Array%(1 TO DimSize) DEF SEG = VARSEG(Array%(1)) BLOAD "ARRAY.BIN",VARPTR(Array%(1)) DEF SEG ... OFFLINE 1.36 --- Maximus 2.01wb * Origin: The BULLpen BBS * Intel 14.4EX (613)549-5168 (1:249/140)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET