[futurebasic] Re: [FB] Still need help with Write File

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 1999 : Group Archive : Group : All Groups

From: David Cottrell <David.Cottrell@...>
Date: Thu, 23 Sep 1999 09:36:12 +1000
>Rick Brown's right on the mark about using WRITE to send a large array to a
>file.
>
>The format is:    WRITE FILE #n, adrr, numBytes
>
>An expression like "@myArray(0)" yields the address where the array starts.
>How to get the number of bytes in the array can be tedious and error prone.
>
>The suggested method to get the number of bytes in the array involved using
>how many elements the array has and multiplying that by the size of each
>element. This is a pain (for me  at least) as I sometimes change the data
>type of the array (poor planning I suppose), especially with strings.
>
>The following approach seems to work well to determine how many bytes are
>in an array. When the array is dimensioned, create another variable
>immediately after. Then subtract their addresses to get the length of the
>first array.
>
>Here's a code sample...
>    -----------------------------------------
>    DIM  myArray(55,23)
>    DIM  myArrayEnd.0
>    '...
>    addr = @myArray(0,0)
>    numBytes = ABS(@myArrayEnd - addr)
>    WRITE FILE #1, addr, numBytes
>    -----------------------------------------
>
>Be sure to use a similar READ FILE instruction to replace the data in
>memory when needed.
>
>This can be adapted to write a whole group of variables to a file in one
>step rather than individually -- just define them one after another in the
>DIMs so that they are in successive bytes of memory and calculate the
>number of bytes from the first variable to extra dummy variable at the end
>of the group.  I imagine this would be one way to save the state of a game
>in progress and continue when you restart, for example.
>
>- Hope this helps a bit.
>  Stu Cram, Regina, Sask. CAN

I'm not sure this will work with FB^3. Arrays are stored differently than
in FBII. Personally, I use a global handle to an array, with XREF@ to
access the indiviual elements. i can then easily get the size of the
handle, and write out any information I need. As for changing the size of
elements I suggest using a constant. Thus you only make the change onece,
and all references to the size of an element will correspond.

The FAQ on XREF@ is very very good.

HTH

David