Post by jarychk on Jul 10, 2022 4:39:26 GMT
This come from the other topic I started, "not know how to APPEND,..."
This is an example program, not yet finished, which lets user build a prenamed file, and view the contents of the file in aligned columns, in a texteditor control. Some problems I needed to watch for and correct were array names misspelling, using wrong variables in loops, and potentially mismatching parentheses.
A reference file, not necessarily the same as the resulting programmatically made file:
---------------------------------------------------------------------------
paco de lucia,1947,2014
paco penya,1942,live
payohumberto,unreport,live
sabicas,1912,1990
ninyo ricardo,1904,1972
melchor de marchena,1907,1980
---------------------------------------------------------------------------
The example program in-progress:
(The extra line spacings here are unintentional. The actual example program doe not contain them.)
This is an example program, not yet finished, which lets user build a prenamed file, and view the contents of the file in aligned columns, in a texteditor control. Some problems I needed to watch for and correct were array names misspelling, using wrong variables in loops, and potentially mismatching parentheses.
A reference file, not necessarily the same as the resulting programmatically made file:
---------------------------------------------------------------------------
paco de lucia,1947,2014
paco penya,1942,live
payohumberto,unreport,live
sabicas,1912,1990
ninyo ricardo,1904,1972
melchor de marchena,1907,1980
---------------------------------------------------------------------------
The example program in-progress:
(The extra line spacings here are unintentional. The actual example program doe not contain them.)
'-----------------------------------------------------------------------------
' VIEW of the file development begins, july 9, 2022
' guitarists_file_study01.bas, the "view" button section
'VARIABLES
dim gtrts$(25,3) 'just want names, year born, year dead, but accepting other data kinds 1 name, 2 bornyear, 3 death year
name$=""
byear$=""
dyear$="" 'year died
nomainwin
WindowWidth = 592
WindowHeight = 555
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #main.button1, "build", [button1Click], UL, 14, 56, 122, 25
button #main.button2, "view", [button2Click], UL, 158, 56, 122, 25
button #main.button3, "make change", [button3Click], UL, 302, 56, 122, 25
texteditor #main.texteditor4, 14, 121, 440, 325
menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "flamenco guitarists list" for window as #main
print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
print #main.texteditor4, "!font Courier 10"
wait
[quit.main]
Close #main
END
[button1Click] 'Perform action for the button named 'button1'
'Insert your own code here
nomainwin
WindowWidth = 560
WindowHeight = 355
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #tofile.statictext1, "In order, give name, year born, year dead. button to add one at time", 22, 41, 488, 30
statictext #tofile.statictext2, "unknown born? say unreported. Not dead? say live.", 22, 76, 400, 20
textbox #tofile.textbox3, 22, 126, 192, 30
textbox #tofile.textbox4, 254, 126, 100, 25
textbox #tofile.textbox5, 374, 126, 100, 25
button #tofile.button6, "record to file", [button6Click], UL, 22, 271, 122, 25
open "guitarists data to file" for window as #tofile
print #tofile, "trapclose [quit.tofile]"
print #tofile, "font ms_sans_serif 10"
WAIT
[button6Click]
print #tofile.textbox3,"!contents? name$"
print #tofile.textbox4,"!contents? byear$"
print #tofile.textbox5,"!contents? dyear$"
'APPEND the file
open "flamguitarists.txt" for APPEND as #g
print #g,name$;",";byear$;",";dyear$
close #g
'clear the text fields
print #tofile.textbox3,"" : print #tofile.textbox4,"" : print #tofile.textbox5,""
wait
[quit.tofile]
close #tofile
wait
[button2Click] 'Perform action for the button named 'button2'
'Insert your own code here
'read file and assign array elements
rec=0
open "flamguitarists.txt" for input as #vu
while eof(#vu)=0
input #vu,name$
input #vu,byear$
input #vu,dyear$
rec=rec+1
gtrts$(rec,1)=name$
gtrts$(rec,2)=byear$
gtrts$(rec,3)=dyear$
wend
close #vu
'display on texteditor4 control
'Use of space$() and len() to control column alignments
print #main.texteditor4,"These ";rec;" flamenco guitarists found."
'column length choices 20 10 10
print #main.texteditor4,"NAME ";"BORN ";"DIED"
for i=1 to rec
print #main.texteditor4,gtrts$(i,1);space$(20-len(gtrts$(i,1)));gtrts$(i,2);space$(10-len(gtrts$(i,2)));gtrts$(i,3) 'code line not show the year number
next i
wait
[button3Click] 'Perform action for the button named 'button3'
'Insert your own code here
wait