Post by jarychk on Jul 7, 2022 23:14:09 GMT
This is a program as a continuation, after making it to show a member here how to open and display a sequential text file.
Now, I thought I would be able easily to extend the program to be able to append new information into the file, but it instead goes into the file wrong, and ruins the form of the file.
Whoever tries to check on this will find most of the trouble happens in the branch for subroutine, [anotherappend].
The file appearing and being now wrong (file been named , pianomencsv.txt :
The sample program:
Now, I thought I would be able easily to extend the program to be able to append new information into the file, but it instead goes into the file wrong, and ruins the form of the file.
Whoever tries to check on this will find most of the trouble happens in the branch for subroutine, [anotherappend].
The file appearing and being now wrong (file been named , pianomencsv.txt :
littlerich,macon,1932
fatsdom,new orleans,1928
jerry,ferriday,1935
proflonghair,bogalusa,1918
Dr. John,new orleans,1941ch. jack
new orleans
1910
fatsdom,new orleans,1928
jerry,ferriday,1935
proflonghair,bogalusa,1918
Dr. John,new orleans,1941ch. jack
new orleans
1910
The sample program:
'csv simple example, to open and read csv file
'name this program boogiecsv.bas
'use the file pianomencsv.txt, 5 rows by 3 columns
'-----------------------------------------------
'file reading ability done. now time to design APPEND ability
' call name of program, boogiecsv01.bas
'VARIABLES
dim who$(15,3)
name$="" 'name of player
bwhere$="" 'born where
byear$="" 'born what year
'i0=0 'loop variable
i1=0 'loop variable
rec=0 'record counter for how many persons
'OPEN THE FILE, LOAD THE ARRAY, CLOSE THE FILE
open "pianomencsv.txt" for input as #pno
while eof(#pno)=0
input #pno,name$
input #pno,bwhere$
input #pno,byear$
rec=rec+1
who$(rec,1)=name$
who$(rec,2)=bwhere$
who$(rec,3)=byear$
wend
close #pno
'DISPLAY ARRAY RECORDS
gosub [showwhodata]
print
input "you wish to add another piano player? ";ans$
whans$=left$(ans$,1)
if whans$="y" or whans$="Y" then
gosub [anotherappend]
end if
'REINITIALIZE PROCESS VARIABLES
gosub [reinitialize]
END
[showwhodata]
print "We identified your ";rec;" piano players."
print
print "PIANO MAN","WHERE BORN","YEAR BORN"
for i0=1 to rec
print who$(i0,1),who$(i0,2),who$(i0,3)
next i0
return
[reinitialize]
name$=""
bwhere$=""
byear$=""
rec=0
return
[anotherappend]
flagbadadd=0
input "piano player ";another$
input "born where, city ";whborn$
input "born in year ";whyear$
if another$="" or whborn$="" or whyear$="" then flagbadadd=1
if flagbadadd=0 then
open "pianomencsv.txt" for append as #nu
print #nu,another$
print #nu,whborn$
print #nu,whyear$
close #nu
else
'reset these variables and leave subroutine
another$=""
whborn$=""
whyear$=""
goto [leaveappend]
end if
[leaveappend]
return