This is a simple and old sequencial file-access snippet :
rem ============================================
rem
rem File Handling Functions & Subs ....
rem
rem by Kohai - black.Olive
rem ============================================
dim filestream$(1000)
rem ******* Vars Inits ....
author$="Author Default"
maxX=0
maxY=0
game_type$="LAND"
Line=0
rem ******* File header
filestream$(Line)="/ Land-a-Luna v0.5"
inc Line,1
filestream$(Line)="/ Map Definition File"
inc Line,1
filestream$(Line)="/ Edited: "+ get Date$()
inc Line,1
filestream$(Line)="/"
inc Line,1
rem ***** author
filestream$(Line)="!author"
inc Line,1
filestream$(Line)=author$
inc Line,1
rem ***** maximums
filestream$(Line)="!maxx"
inc Line,1
filestream$(Line)=str$(maxX)
inc Line,1
filestream$(Line)="!maxy"
inc Line,1
filestream$(Line)=str$(maxY)
inc Line,1
filestream$(Line)="!game_type"
inc Line,1
filestream$(Line)=game_type$
inc Line,1
filestream$(Line)="!end"
inc Line,1
print "left for write, right for read, space to finish!"
do
if leftkey() then gosub WriteMap
if rightkey() then gosub ReadMap
if spacekey() then exit
loop
undim filestream$(1000)
end
WriteMap:
cls 0
for i=0 to Line
print filestream$(i)
Next i
rem Clear screen
``cls rgb(rnd(100),rnd(100),rnd(100))
rem Delete file
if file exist("mymap.def") then delete file "mymap.def"
rem Write or Read..
rem Open file for writing
open to write 1,"mymap.def"
rem Write data types
for i=0 to Line
write string 1,filestream$(i)
Next i
rem Close file
close file 1
print "File closed - Hit a key !"
suspend for key
cls 0
print "left for write, right for read, space to finish!"
return
ReadMap:
dim dummy$(1000)
cls 0
rem Open file for reading
open to read 1,"mymap.def"
rem Display data types
while file end(1)=0
read string 1,dummy$(i)
inc i,1
endwhile
rem Close file
close file 1
print "processing ...."
i=0
do
rem
rem on pourra rajouter d'autre commandes, selon les besoins
rem
if left$(dummy$(i),1)="/" then inc i,1 : print " dummy found."
if left$(dummy$(i),5)="!auth" then author$=dummy$(i+1): print "author found."
if left$(dummy$(i),5)="!maxx" then maxX=val(dummy$(i+1)): print "maxx found."
if left$(dummy$(i),5)="!maxy" then maxY=val(dummy$(i+1)): print "maxy found."
if left$(dummy$(i),5)="!game" then game_type$=dummy$(i+1): print "type found."
if left$(dummy$(i),4)="!end" then exit
inc i,1
loop
cls 0
undim dummy$(1000)
print "Author: ",author$
print "Maximum X: ",maxX
print "Maximum Y: ",maxY
print "Game Type: ",Game_type$
suspend for key
cls 0
print "left for write, right for read, space to finish!"
return
Now concerning a CSV (Comma Separated Vars ) format parser, try to look at the mistr$() & instr$() functions, posted in this thread :
http://www.darkbasicpro.com/apollo/view.php?t=1854&b=6
Basically, what you do is get the first comma in line. You then extract tha datas between start_of_line & comma_pos. Do this for each comma, and there you have a CSV parser ! ^^
[Kohai]
[url]www.underwaredesign.com[url] [url]kohaistyle.com[url]
pIII 733/256 Ram/Geforce 256