|
Post by tsh73 on Apr 13, 2018 10:59:40 GMT
WAIT in a function is bad thing. In JB/LB. That's why:
' Form created with the help of Freeform-J v.261006 ' Generated on Apr 13, 2018 at 13:47:19
nomainwin
WindowWidth = 344 WindowHeight = 220
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "Press button 1. It will cal WAIT in a function. Now try any button/trapclose. Probably all labels will be unreachable.", 26, 16, 288, 50 statictext #main.statictext1, "(you better close with KillBasic Progam from JB IDE)", 26, 70, 288, 80 button #main.button1, "Button1", [button1Click], UL, 30, 141, 122, 25 button #main.button2, "Button2", [button2Click], UL, 190, 141, 122, 25 open "wait in function - test" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
wait
[quit.main] Close #main END
[button1Click] 'Perform action for the button named 'button2' notice "Button 1 clicked" dummy = someFunction() wait
[button2Click] 'Perform action for the button named 'button3' 'Insert your own code here notice "Button 2 clicked" wait
function someFunction() notice "We are in a function" wait 'this one probably should't be done [button1Click] notice "this label1 is available in a function" wait end function
My guess that after WAIT JB waits on the spot it happened. That is, inside function. So no labels are visible that is outside this function (but label inside it are visible - button 1 works, with new label)
|
|
|
Post by carlgundel on Apr 14, 2018 3:40:33 GMT
Yeah, I would suggest that almost always, an event handler for button clicks, etc. should be top level subs and branch labels and not inside of subs/functions. There may be some circumstances where it makes sense to do it, but for the most part, no.
|
|
Pale
Member in Training
Posts: 25
|
Post by Pale on Apr 26, 2018 15:57:00 GMT
A way of making a window modal. Any clicks on the higher level window throws up an error as the label to goto is missing (in the function), but it does not crash the program. You could add all the higher level labels to the function to trap this so that nothing happens until the new window is closed. There is probably a better way to do this but I am new to JB.
|
|
|
Post by B+ on Apr 26, 2018 16:34:53 GMT
A way of making a window modal. Any clicks on the higher level window throws up an error as the label to goto is missing (in the function), but it does not crash the program. You could add all the higher level labels to the function to trap this so that nothing happens until the new window is closed. There is probably a better way to do this but I am new to JB. Yes, as I recall a window or graphics screen can be opened in modal mode. See Help, jb20help * GUI Programming > * Window Types (about midway down the scroll bar)
|
|
Pale
Member in Training
Posts: 25
|
Post by Pale on Apr 28, 2018 19:44:24 GMT
Did you mean "can't be opened in modal"
open "Level 1 display" for window_modal as #level1
Fails Bad file mode: WINDOW_MODAL
|
|
|
Post by tsh73 on Apr 28, 2018 20:28:36 GMT
Help page "Window Types" lists all existing types of windows. Only "modal" are dialogs.
|
|
|
Post by B+ on Apr 28, 2018 20:36:35 GMT
Did you mean " can't de opened in modal" open "Level 1 display" for window_modal as #level1 Fails Bad file mode: WINDOW_MODAL Did you read the Help? there is not a WINDOW_MODAL that I could see (the complete list of Window types were listed below) there was this that might be the type you seek. open "Level 1 display" for dialog_modal as #level1 #level1 "trapclose [quit]"
[quit] close #level1
I am just trying to help you find a less complicated way for modal functionality. Dang tsh73 posted while I was writing up mine!
|
|
|
Post by tsh73 on Apr 28, 2018 21:52:00 GMT
Terseness makes you keyboard ninja
|
|
Pale
Member in Training
Posts: 25
|
Post by Pale on Apr 30, 2018 8:25:57 GMT
Did you mean " can't de opened in modal" open "Level 1 display" for window_modal as #level1 Fails Bad file mode: WINDOW_MODAL Did you read the Help? there is not a WINDOW_MODAL that I could see (the complete list of Window types were listed below) there was this that might be the type you seek. open "Level 1 display" for dialog_modal as #level1 #level1 "trapclose [quit]"
[quit] close #level1
I am just trying to help you find a less complicated way for modal functionality. Did you read MY post ? Did you read YOUR OWN post? Read YOUR first post .YOU are the one saying there is a modal type for window. As I pointed out, I believe you made a typo in your post saying the opposite to what you meant. My piece of code is to demonstrate that there is NO window_modal . It is not a piece of code I am using. A bit of proof reading saves a lot of confusion. I'm not the one chasing modal forms . I just mentioned something I had noticed . Pale ( something screwy with this BB quoting system or firefox is being an arse again)
|
|
|
Post by B+ on Apr 30, 2018 13:06:57 GMT
Did you read the Help? there is not a WINDOW_MODAL that I could see (the complete list of Window types were listed below) there was this that might be the type you seek. open "Level 1 display" for dialog_modal as #level1 #level1 "trapclose [quit]"
[quit] close #level1
I am just trying to help you find a less complicated way for modal functionality. Did you read MY post ? Did you read YOUR OWN post? Read YOUR first post .YOU are the one saying there is a modal type for window. As I pointed out, I believe you made a typo in your post saying the opposite to what you meant. My piece of code is to demonstrate that there is NO window_modal . It is not a piece of code I am using. A bit of proof reading saves a lot of confusion. I'm not the one chasing modal forms . I just mentioned something I had noticed . Pale ( something screwy with this BB quoting system or firefox is being an arse again) Hi Pale, When you said, "A way to making a window modal." I thought you were suggesting a way for a window to FUNCTION modally because you described some complicated procedure. I tried to point you to help section that described Window Types for an easier way to get a window to FUNCTION modally. There is a way for a Window to FUNCTION modally just by setting the proper mode (which I did not know at time, so just pointed you to Help section). I never said WINDOW_MODAL was what you should try. It's true I do not understand why you brought up the subject in the first place. I did not read/comprehend how it follows from what was said before.
|
|
Pale
Member in Training
Posts: 25
|
Post by Pale on Apr 30, 2018 19:13:49 GMT
A way of making a window modal. Any clicks on the higher level window throws up an error as the label to goto is missing (in the function), but it does not crash the program. You could add all the higher level labels to the function to trap this so that nothing happens until the new window is closed. There is probably a better way to do this but I am new to JB. Yes, as I recall a window or graphics screen can be opened in modal mode. Yes you do just there in the bottom line of the top quote above, but I believe this is not what you meant. The "can" should be a "can't". tsh73 said that WAIT in a function is a bad thing. Mostly yes, but not always ,it can be used to ones advantage ie making a window modal as there is not a way of doing this natively. I was just suggesting a method that might help others achieve this by putting window operations inside a function then the wait. this effectively make the new window modal . I then go on to say that this is a little messy due to the labels for any events will be missing unless you put copies in the function too. I am actually using this in my current project to stop duplicate window handles crashing the program. tsh73 was making a good point and I as just adding a silver lining to it by suggesting how this limitation can be used to ones advantage. What upset me was being accused of not reading the manual when the accuser had obviously not read my or his own posts. Storms in tea cups .
|
|
|
Post by Rod on Apr 30, 2018 19:37:09 GMT
I have actually used that trick of defining dummy labels in side a function. When I first posted the code there was complete polite silence from the gurus. They either had not thought of it or were appalled at the cheat.. Since I have never seen the trick repeated in fifteen years of coding I have to assume they were appalled.
You can do dialogue modal if you have to hold focus. You can switch everything off and wait for the one event that matters. Thing is that Just BASIC can allow all sorts of coding and if it works it works.
But i don’t use dummy labels anymore, one ominous silence was enough for me.
|
|
Pale
Member in Training
Posts: 25
|
Post by Pale on Apr 30, 2018 20:13:27 GMT
I just stumbled across it whilst trying to reduce code size and passing parameters. I put my child window in a function and then by accident reselected the button that opened the window and it didn't crash the program as it had before with duplicate file handle. I twigged it was using the local variables , but hey it stopped the crash so I went with the flow. Assuming a dialogue could have graphics boxes in them then that would be neater , but that would mean even more rewriting that just isn't worth it on this application.
Pale
|
|
|
Post by tsh73 on May 1, 2018 7:59:09 GMT
Pale, really interesting. Do you have a small demo?
|
|
Pale
Member in Training
Posts: 25
|
Post by Pale on May 1, 2018 20:06:40 GMT
This is hacked out of my program so some of the variables etc may have odd names.
WindowWidth = 550 WindowHeight = 420 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #main.button1, "Button 1", [button1Click], UL, 14, 31, 138, 25 button #main.button2, "Button 2", [button2Click], UL, 160, 31, 150, 25 button #main.button7, "open a new window", [button7Click], UL, 334, 31, 170, 25 button #main.button13, "Exit", [button13Click], UL, 44, 251, 42, 25
open "Test " for window as #main print #main, "font ms_sans_serif 0 16"
[main.inputLoop] 'wait here for input event wait
[button1Click] notice "from main window" wait
[button2Click] notice " from main window" wait
[button7Click] 'display level 1 'Insert your own code here temp = displaylevel1() wait
[button13Click] 'exit close #main end wait
goto [main.inputLoop]
'***********************************************************level 1 data Display ************************************** function displaylevel1() [displaylevel1]
WindowWidth = 300 WindowHeight = 300 gboxmaxwidth = 400 ' set width for graphics bug work around gboxmaxheight = 400 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #level1.close," Close ", [closelevel1],ul, 20,10 button #level1.print," Print ", [printlevel1],ul, 120,10
graphicbox #level1.g, 5, 55, (WindowWidth - 20), (WindowHeight-85 ) open "Level 1 display" for window as #level1 print #level1, "trapclose [closelevel1]" print #level1.g, "vertscrollbar on 0 ";(gboxmaxheight - WindowHeight) ' scroll bar offest varies with window size print #level1.g, "horizscrollbar on 0 ";(gboxmaxwidth - WindowWidth) ' scroll bar offest varies with window size print #level1.g, "down; color black; backcolor white" print #level1.g, "place 0 0 ; boxfilled ";gboxmaxwidth;" ";gboxmaxheight 'IMPORTANT fontsize = int(16*scale) 'bug work around print #level1.g, "font Times_New_Roman 0 ";fontsize title$ = "Some" print #level1.g,"place ";20;" ";25;" ; down " print #level1.g, "\";title$ title$ = "Random" print #level1.g,"place ";140;" ";25 print #level1.g, "\";title$ title$ = "Text" print #level1.g,"place ";240;" ";25 print #level1.g, "\";title$ print #level1.g, " up "
print #level1.g, "flush" ' make stick wait
[printlevel1] notice "you dont realy want to print" 'print #level1.g, "print " wait [button1Click] notice "inside function" wait [button2Click] notice "inside function" wait [button13Click] 'exit notice "you cant exit from inside the function" wait [closelevel1] close #level1 [returnlevel1] ' return end function
click button 1 or 2 gives a message. the open a new window button opens a window with more buttons and a graphic box. This new window is in a function. If you now click one of the buttons in the original window it goes to the label in the function not the original one. If these are just populated with a wait statement then nothing will happen. I put a notice there so that you can see where the program is pointing. If you click the open a new window button wilst the new window is open you can see the label not found message as there is no label for this button inside the function. i left it like this so you can see the error If the new window was not a function then clicking the "open a new window" button would cause the new window code to be called again and it would try to use the same handle crashing the program. I have recently seen a bit of code that sets a string and uses that for the handle thus you could keep a counter to ensure unique handles, or set some flag to stop you opening another window. just another method.
As you say the WAIT is definitely in the function
|
|