Post by tsh73 on Nov 19, 2022 14:43:37 GMT
About closing cross, I see three ways
1) do not check. If user press ESC so be it - close
(of course it could drive one crazy if data is lost.
But - programmer could save data on close and reload on restart, like i did here)
2) Just do ask if user really wants to close. This is minor nuisance and most people would not even think while pressing Yes
3) redirect to special "Close" button
I did all three as a radiobuttons here, give them a try.
Now, (3) is somewhat rude, (1) could leave you briefless if you suddenly press ESC
So I think best option is (2)
1) do not check. If user press ESC so be it - close
(of course it could drive one crazy if data is lost.
But - programmer could save data on close and reload on restart, like i did here)
2) Just do ask if user really wants to close. This is minor nuisance and most people would not even think while pressing Yes
3) redirect to special "Close" button
I did all three as a radiobuttons here, give them a try.
Now, (3) is somewhat rude, (1) could leave you briefless if you suddenly press ESC
So I think best option is (2)
' Form created with the help of Freeform-J v.261006
' Generated on Nov 19, 2022 at 17:22:02
nomainwin
WindowWidth = 520
WindowHeight = 215
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "this piece of data will be saved", 22, 16, 216, 20
texteditor #main.texteditor2, 30, 41, 184, 110
groupbox #main.groupbox3, " on closing window ", 238, 26, 256, 95
radiobutton #main.rbNoAsk, "do close", [dummy], [dummy], 254, 46, 80, 20
radiobutton #main.rbAsk, "do ask", [dummy], [dummy], 254, 66, 64, 20
radiobutton #main.rbRefer2CloseBtb, "refer to Close buttnon", [dummy], [dummy], 254, 86, 192, 20
button #main.rtnClose, "Close", [rtnCloseClick], UL, 366, 126, 122, 25
'*** menus are not supported in windows of type dialog_nf ***
menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "So dialog is closing on ESC. Hmmm..." for dialog_nf as #main
print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
#main.rbNoAsk "set"
saveFileName$ = "savedata19112022.txt"
if fileExists(DefaultDir$, saveFileName$) then
open saveFileName$ for input as #1
#main.texteditor2, "!contents #1"
close #1
else
#main.texteditor2, "This text will be retained"
#main.texteditor2, "for next start."
#main.texteditor2, " Try to change it."
end if
wait
[quit.main]
'read radiobuttins
#main.rbNoAsk "value? result$"
if result$ = "set" then [noQuestionsClose]
#main.rbAsk "value? result$"
if result$ = "set" then
confirm "Are you sure you want to close";result$
if result$ = "yes" then [noQuestionsClose]
wait 'else, do not close
else
'else it oulghg to be #main.rbRefer2CloseBtb
notice "please use Close button"
wait
end if
[noQuestionsClose]
'but save the data
open saveFileName$ for output as #1
#main.texteditor2, "!contents? string$"
print #1, trim$(string$)
close #1
Close #main
END
[dummy] 'no immediate action for the radiobuttons
wait
[rtnCloseClick] 'Perform action for the button named 'rtnClose'
goto [noQuestionsClose]
wait
'from a help file
function fileExists(path$, filename$)
'dimension the array info$( at the beginning of your program
dim info$(10, 10)
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
end function