xcoder
Member in Training
Posts: 56
|
Post by xcoder on Oct 14, 2022 3:57:27 GMT
How do I trap the "cancel" and "red x" buttons on a File Dialog Window?
|
|
|
Post by tsh73 on Oct 14, 2022 6:06:23 GMT
from a Help file
So if returned string is empty, that means user pressed Cancel button/ ESC/ redX in the corner.
filedialog "Open text file", "*.txt", fileName$ if fileName$<>"" then print "you selected a file" print fileName$ else print "User cancelled dialog" end if
|
|
xcoder
Member in Training
Posts: 56
|
Post by xcoder on Oct 14, 2022 15:04:47 GMT
The given code does not prevent a GUI program from showing "file handles not closed" and generating a Error.
|
|
|
Post by tsh73 on Oct 14, 2022 16:20:56 GMT
Given code does not open a thing, so it has nothing to close. How about posting your code? Folks might spot the error.
|
|
|
Post by Rod on Oct 14, 2022 18:53:18 GMT
Yes, if the programmer opens a resource it is up to the programmer to close thst resource with trapclose or close. If you leave a window open and quit or crash without closing it you will get an error. But showing us your code is the fastest fix.
|
|
|
Post by xxgeek on Oct 16, 2022 23:41:57 GMT
a simple example:
open "test" for window as #testWindow #testWindow "trapclose [quit]"
filedialog "Open \ Select a File (.bas) ", DefaultDir$; "\*.bas", fname$ if fname$ = "" then notice "No file selected" print fname$
[quit] close #testWindow end
|
|
xcoder
Member in Training
Posts: 56
|
Post by xcoder on Oct 17, 2022 23:39:49 GMT
Now select the "cancel" button or the red "X" button on FileDialog and see what happens!
|
|
|
Post by xxgeek on Oct 18, 2022 3:59:04 GMT
Is this what you're looking for? No notice, and leave the window open?
Without seeing your code it's a shot in the dark.
open "test" for window as #testWindow #testWindow "trapclose [quit]"
filedialog "Open \ Select a File (.bas) ", DefaultDir$; "\*.bas", fname$ if fname$ = "" then doNothing = 1 wait
[quit] close #testWindow end
|
|
xcoder
Member in Training
Posts: 56
|
Post by xcoder on Oct 21, 2022 0:40:05 GMT
That is it exactly. I am writing a "file pass" program.
|
|
|
Post by xxgeek on Oct 21, 2022 19:00:29 GMT
That is it exactly. I am writing a "file pass" program. You mean like a file sharing app?
|
|
xcoder
Member in Training
Posts: 56
|
Post by xcoder on Oct 26, 2022 1:04:16 GMT
I figured it out already. Full code will be posted soon.
|
|