|
Post by TheSquirrelly1 on Jun 27, 2004 12:53:13 GMT -5
I would like to import my tile data...
e.g.
Data 0,0,0,0,0,0,0 Data 1,3,0,0,0,0,0 Data 1,1,1,1,1,1,4
From a file...
How might I do this in Basic4GL?
Thanks,
Squirrelly1
|
|
|
Post by NoVaGene on Jun 27, 2004 16:19:22 GMT -5
Try this:-
dim file, read_text$, skipEOL, value(21), inc skipEOL=true 'to skip whitespaces inc=0
locate 2,5 file = OpenFileRead ("files\data.txt") if FileError () <> "" then print FileError (): end: endif
while not EndOfFile (file) read_text$ = readtext(file, skipEOL) value(inc)=val(read_text$) 'printr value(inc) ' un-comment to chk correctness of values inc=inc+1 wend CloseFile (file)
Have your data.txt in basic4gl files folder 1st and Replace all the "," to " " in the file. Change the dim value 21 to suit your size of data.
Spend sometime to take a look at the Programmer's guide for detailed explanations.
Cheers! Lucas Tan
|
|
|
Post by AHBanen on Jun 27, 2004 17:19:49 GMT -5
Lucas, Because it is possible to re-use the code you gave to read all kinds of files - even empty ones - I suggest a change to the loop: Coded this the problems of failing to read something and and trying to assign it anyway to a variable are avoided. Structured and well behaved programming is possible in Basic4GL (if you want ). André
|
|