I think that some people (new to DBC/DBP) do not know how to "write to" and "read from" files.
This is the first chapter of an intro "how to" do it.
If your are interested in the consequent chapters please let me know and I will post them here.
Attila
p.s. As download the project description (as PDF) is attched (link: [href]
forumfiles.thegamecreators.com/download/2469351[/href])
Code:
`------------------------------------------------------------------------------
` Setting up the environment
`------------------------------------------------------------------------------
set window on
set window layout 1,1,1
set window title "Write Data to a file"
set window size 800,600
set display mode 800,600,screen depth()
set text size 10
set text font "Arial"
ink rgb(255,255,0),0
`------------------------------------------------------------------------------
` if there is no data file then create an empty one
`------------------------------------------------------------------------------
HomeDir$=get dir$()
print HomeDir$
if right$(HomeDir$,1) <> "\" then HomeDir$=HomeDir$+"\"
if file exist(HomeDir$+"addr.txt") = 0
open to write 1, HomeDir$+"addr.txt"
write string 1,"! Created "+get date$()+" "+get time$()
close file 1
endif
`------------------------------------------------------------------------------
` Enter Data
`------------------------------------------------------------------------------
while EndIt=0
cls
set text size 15
set text to bold
text 10,5,"My first Address-Collection"
set text size 10
set text to normal
text 10,30,"family name:"
text 160,30,"________________________"
text 10,45,"Christian name:"
text 160,45,"________________________"
text 10,60,"Street and Number:"
text 160,60,"________________________"
text 10,75,"Zip/postal code:"
text 160,75,"________________________"
text 10,90,"Town:"
text 160,90,"________________________"
text 10,105,"Country:"
text 160,105,"________________________"
family_name$="" :` make sure the variable family_name iss empty
set cursor 160,30
input family_name$
if family_name$ <> ""
family_name$=left$(family_name$,30)
set cursor 160,45
input christian_name$
christian_name$=left$(christian_name$,30)
set cursor 160,60
input street_and_number$
street_and_number$=left$(street_and_number$,30)
set cursor 160,75
input postal_code$
postal_code$=left$(postal_code$,10)
set cursor 160,90
input town$
town$=left$(town$,30)
set cursor 160,105
input county$
country$=left$(country$,30)
endif
if family_name$=""
EndIt=-1
else
`------------------------------------------------------------------------------
` Store Record
` DBC/DBP do not provide an "open append" command therefore
` we must read the whole file an copy it to a new one
`------------------------------------------------------------------------------
`------------------------------------------------------------------------------
` Creating the output-string (outp$) using fixed field legnth as
` defined in the project
`------------------------------------------------------------------------------
outp$="" : ` Clear the outp$
while len(family_name$) < 30 : family_name$=family_name$+" ":endwhile
while len(christian_name$) < 30 : christian_name$=christian_name$+" ":endwhile
while len(street_and_number$) < 30 : street_and_number$=street_and_number$+" ":endwhile
while len(postal_code$) < 10 : postal_code$=postal_code$+" ":endwhile
while len(town$) < 30 : town$=town$+" ":endwhile
while len(country$) < 30 : country$=country$+" ":endwhile
`------------------------------------------------------------------------------
` Put it together
`------------------------------------------------------------------------------
outp$=family_name$+christian_name$+street_and_number$+postal_code$+town$+country$
`------------------------------------------------------------------------------
` Appending to the file
`------------------------------------------------------------------------------
if file exist(HomeDir$+"addr.txt")
if file exist(HomeDir$+"addr.old")
delete file HomeDir$+"addr.old"
endif
rename file HomeDir$+"addr.txt", HomeDir$+"addr.old"
open to read 1, HomeDir$+"addr.old"
open to write 2, HomeDir$+"addr.txt"
while file end(1)=0
read string 1, rec$
write string 2, rec$
endwhile
close file 1
write string 2, Outp$
close file 2
endif
endif
endwhile
end