This works in non-carbon:
===============
DIM AS BOOLEAN Done
_MaxRecords = 50
DIM RECORD ItemRCRD
DIM Iden%
DIM 15 Nme$
DIM Inv%
DIM 1 Place$
DIM Price#
DIM END RECORD _ItemRCRD
DIM Item.ItemRCRD
DIM Temp.ItemRCRD
DIM List.ItemRCRD ( _MaxRecords )
arraySize& = _MaxRecords * 26
arrayPointer& = VARPTR ( List ( 0 ) )
---- snip
LOCAL FN SaveData
PRINT "Saving data..."
filename$ = FILES$(_fSave,"Save As..","Inventory.dat",volRefNum%)
LONG IF LEN(filename$) > 0
List.Nme$(0) = "How Many"
List.Inv%(0) = 0
List.Place$(0) = " "
List.Price#(0) = 0.0
OPEN "O",1, filename$,,volRefNum%
WRITE FILE #1,arrayPointer&,arraySize&
CLOSE #1
XELSE
PRINT "Save Canceled"
DELAY 1000
END IF
END FN
LOCAL FN LoadData
PRINT "Loading Data..."
filename$ = FILES$(_fOpen,"",,volRefNum%)
LONG IF LEN(filename$) > 0
OPEN "I",1, filename$,,volRefNum%
READ FILE #1,arrayPointer&,arraySize&
CLOSE #1
XELSE
PRINT "File Not Loaded!!"
List.Iden%(0) = 0
List.Nme$(0) = "How Many"
List.Inv%(0) = 0
List.Place$(0) = "."
List.Price#(0) = 0.0
END IF
END FN
-----Original Message-----
From: barrie [mailto:barrie@...]
Sent: Tuesday, April 29, 2003 7:16 PM
To: futurebasic@...
Subject: [FB] WRITE FILE# and READ FILE #
I'm having a problem writing and reading files. Will someone please check
the following. In particular the WRITE FILE and READ FILE syntax. The array
data is OK before it is saved, but it is corrupt when I read it. The number
of records reads correctly with LOF(1)
Thanks
Barrie
LOCAL FN SaveDataRecord
dim as long dataBytes,recordSize,timeBytes,locationBytes
FN getDateAndTime
DEF OPEN ="DataCHMK"
dataBytes = ((_maxAnswers+1)*(_maxQuestions+1)) * SIZEOF(INT)
timeBytes = SIZEOF(INT) * 6
locationBytes = SIZEOF(gLocation$)
recordSize = dataBytes + timeBytes + locationBytes
OPEN "A",1,gSurveyDataFile$,recordSize,0
PRINT #1,gLocation$
WRITE FILE #1, @gTimeStamp%(0),timeBytes
WRITE FILE #1, @gData%(0,0),dataBytes
CLOSE #1
def blockfill(@gData(0,0), (_maxAnswers+1) * (_maxQuestions+1) *
sizeof(gData(0,0)), 0)
END FN
LOCAL FN ReadDataRecord(recordNum,positionInRecord)
dim as long dataBytes,recordSize,timeBytes,locationBytes
dataBytes = ((_maxAnswers+1)*(_maxQuestions+1)) * SIZEOF(INT)
timeBytes = SIZEOF(INT) * 6
locationBytes = SIZEOF(gLocation$)
recordSize = dataBytes + timeBytes + locationBytes
DEF OPEN ="Data"
gSurveyDataFile$ = FILES$ (_fOpen,"Data","Open Data file",gFileVol)
IF gSurveyDataFile$ = "" THEN exit fn
OPEN "I",1,gSurveyDataFile$,recordSize,gFileVol
gNumberOfRecords = LOF(1)
RECORD 1,recordNum ,positionInRecord
INPUT #1,gLocation$
READ FILE #1, @gTimeStamp%(0),timeBytes
READ FILE #1, @gData%(0,0),dataBytes
CLOSE #1
END FN
--
To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>