mack
New Member
Posts: 6
|
Post by mack on Sept 18, 2021 13:00:17 GMT -5
Hi
I simply cannot get my head round this. I have even tried using Beginning Programming for Dummies which I usually find quite helpful.
I am looking for the code whereby I close this program and the next time I open it the figure in the Total box is still there.
Regards
Robert
nomainwin
button #win.run, "Run",[Run], LR, 25, 15, 40, 30
statictext #win.1, "Value", 10, 10, 75, 25
statictext #win.2, "Value", 10, 50, 75, 25
statictext #win.3, "Total", 10, 90, 75, 25
textbox #win.1, 100, 10, 50, 25
textbox #win.2, 100, 50, 50, 25
textbox #win.total 100, 90, 50, 25
open "Test" for window as #win
[Run]
print #win.1, "!contents? number1"
print #win.2, "!contents? number2"
total = number1 * number2
print #win.total, total
print #win, "trapclose [quit]"
wait
[quit]
confirm "Close?"; quit$
if quit$ = "No" then wait
close #win
close #1
end
|
|
|
Post by Chris Iverson on Sept 18, 2021 13:41:07 GMT -5
Variables do not persist across executions. If you need data to persist, you have to persist it yourself.
The most common way to do that is to save it to a file, and load it when you start the program.
The book you're using should have chapters dealing with file I/O.
I'm away from my computer at the moment, or I'd whip up a quick example of how to do it.
|
|
|
Post by tsh73 on Sept 18, 2021 14:49:04 GMT -5
Here's my attempt at doing it Only problem - saving numbers saves 0 even if textbox is empty Way around is save text, but you seem to use them as numbers so I kept it.
nomainwin filename$ = "data321.txt" dim info$(0, 0) 'for fileExsists
button #win.run, "Run",[Run], LR, 25, 15, 40, 30
statictext #win.1, "Value", 10, 10, 75, 25 statictext #win.2, "Value", 10, 50, 75, 25 statictext #win.3, "Total", 10, 90, 75, 25 textbox #win.1, 100, 10, 50, 25 textbox #win.2, 100, 50, 50, 25 textbox #win.total 100, 90, 50, 25
open "Test" for window as #win print #win, "trapclose [quit]"
'check if file exists, if so, read data and put them in textboxes if fileExists(DefaultDir$, filename$) then 'read the data open filename$ for input as #1 if not(eof(#1)) then 'is where any data? input #1, number1 print #win.1,number1 end if if not(eof(#1)) then input #1, number2 print #win.2,number2 end if if not(eof(#1)) then input #1, total print #win.total, total end if close #1 end if wait
[Run] print #win.1, "!contents? number1" print #win.2, "!contents? number2" total = number1 * number2 print #win.total, total wait
[quit] confirm "Close?"; quit$ if quit$ = "no" then wait 'actually small 'no' 'before closing, save the data print #win.1, "!contents? number1" print #win.2, "!contents? number2" print #win.total, "!contents? total" open filename$ for output as #1 print #1, number1 print #1, number2 print #1, total close #1 close #win end
'from the help file function fileExists(path$, filename$) 'dimension the array info$( at the beginning of your program files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
|
Post by tsh73 on Sept 18, 2021 14:54:10 GMT -5
OK new with saving/loading text strings - preserve empty textboxes
nomainwin filename$ = "data321.txt" dim info$(0, 0) 'for fileExsists
button #win.run, "Run",[Run], LR, 25, 15, 40, 30 button #win.clr, "Clear",[Clear], LR, 75, 15, 40, 30
statictext #win.1, "Value", 10, 10, 75, 25 statictext #win.2, "Value", 10, 50, 75, 25 statictext #win.3, "Total", 10, 90, 75, 25 textbox #win.1, 100, 10, 50, 25 textbox #win.2, 100, 50, 50, 25 textbox #win.total 100, 90, 50, 25
open "Test" for window as #win print #win, "trapclose [quit]"
'check if file exists, if so, read data and put them in textboxes if fileExists(DefaultDir$, filename$) then 'read the data open filename$ for input as #1 if not(eof(#1)) then 'is where any data? input #1, number1$ print #win.1,number1$ end if if not(eof(#1)) then input #1, number2$ print #win.2,number2$ end if if not(eof(#1)) then input #1, total$ print #win.total, total$ end if close #1 end if wait
[Run] print #win.1, "!contents? number1" print #win.2, "!contents? number2" total = number1 * number2 print #win.total, total wait
[Clear] print #win.1,"" print #win.2,"" print #win.total,"" wait
[quit] confirm "Close?"; quit$ if quit$ = "no" then wait 'actually small 'no' 'before closing, save the data print #win.1, "!contents? number1$" print #win.2, "!contents? number2$" print #win.total, "!contents? total$" open filename$ for output as #1 print #1, number1$ print #1, number2$ print #1, total$ close #1 close #win end
'from the help file function fileExists(path$, filename$) 'dimension the array info$( at the beginning of your program files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
mack
New Member
Posts: 6
|
Post by mack on Sept 19, 2021 14:20:17 GMT -5
That's interesting thank you. I will study the code.
|
|