|
Post by tsh73 on Jun 26, 2023 9:38:50 GMT -5
And here is a modern way to program it. LOL Looks nicer, sure.
But could you actually use it (without rewriting rest of the program that is)? Because you cannot jump to [module1] from inside sub module h$, no way.
|
|
|
Post by Rod on Jun 26, 2023 10:33:58 GMT -5
From a beginners point of view it is important to realise that the program flow will always branch and return from the WAIT statement.
So while the sub is shown as multi functional you could have three subs for each option. But then it is little different from the [branch] code other than the fact that there would be three WAITs instead of of one.
|
|
|
Post by bushrat on Jun 27, 2023 20:07:29 GMT -5
Anatoly I've implemented all your coding with a couple of changes and everything runs smoothly. Your coding comments were very helpful.
The statment that always bugs me is the 'wait' statement, it often appears like it's doing nothing - sort of suspended in mid-air - if it was coded as
wait goto [xxxxx]
then it would be a lot more comprehensible to a beginner showing what it was going to do after detecting some user input? but when I came across
wait 'do nothing here
I was always puzzled as to how the program advances from that point. I guess it just advances on its return to execute the next instruction. I'm getting used to it.
Quote from Rod. "From a beginners point of view it is important to realise that the program flow will always branch and return from the WAIT statement." That was a useful comment.
Later I will implement another of Rod's suggestions to abandon radiobuttons and use ordinary buttons - though I think radiobuttons are sexier. Your comment when using radiobuttons to pre-select the first one was also something I wasn't aware of and it simplifies the program flow.
So now I'm crusing merrily along waiting to hit the next iceberg...
Thanks to all for your great assistance, I was going nowhere without it.
|
|
|
Post by tsh73 on Jun 28, 2023 2:03:31 GMT -5
The point is,
wait goto [xxxxx] is never going to work. You never get post WAIT statement.
Think of it like program is going to some suspended state after WAIT It sits where until some event happeneng It that case, program goes to that event handler (button click, whatever). (not single point of resuming execution, but different possible ppoints depending on what events you are listening to) If you have no events listening - nothing would ever happen
|
|
|
Post by bushrat on Jun 28, 2023 3:39:13 GMT -5
ah, now I see what wait is doing. I thought it was a single point which listened then returned to that place to resume execution, but if execution resumes depending on where control is directed by a user event then it all starts to make sense.
I bet there's a lot of LB users like myself who have used LB for many years successfully but who have major gaps in their fundamental understanding of GUI structure. I'm thinking of creating a post with a proper heading, say, "Simple GUI coding in LB v.4.5.1" and collecting all the posts I've recently made and replies to them by those who have helped me so that anyone starting from scratch could follow through the process and gain a better understanding of what they're doing? Is that a good idea? I'd just copy/paste everything under a new topic heading.
|
|
|
Post by tsh73 on Jun 28, 2023 6:44:01 GMT -5
Trying to explain to others is sure way to get better understanding. Just not simply copy/paste. Make it structured.
|
|
|
Post by Gordon Rahman on Jun 28, 2023 18:28:23 GMT -5
I love GOTO .... it WAITS where you tells it to WAIT. I love GOSUB ... RETURN (it returns to the "caller") I love SUB ..... END SUB (it returns to the caller and you can CALL a SUB with parameters.)
subs have advantages and disadvantages .... it knows local variabeles but it has a narrow scope ( so you can't mix it with gosubs). subs ... and objects rule the world nowadays because they made possible ... building large programs ... in seperate teams at different locations. LibertyBASIC uses all three and LibertyBASIC is te most easy programming language on the doorstep to OOP programming.
|
|
|
Post by Walt Decker on Jun 28, 2023 18:48:51 GMT -5
Not quite correct. GOSUB/GOTO can be used as easily within a sub/function as outside it.
ADDED: Provided that the target of the GOSUB/GOTO is within the code space of the SUB/FUNCTION procedure.
' SUB FOO Varb1, Varb2, Varb3
'some code GOSUB [DO.SOMETHING]
'more code
EXIT SUB
[DO.SOMETHING] ' code RETURN
END SUB '
The GOSUB procedure will work only with the variables within the SUB/FUNCTION module unless it is referencing GLOBAL variables.
|
|
|
Post by Gordon Rahman on Jun 29, 2023 17:57:51 GMT -5
hmmm .... maybe I should have elaborate on this.
Thanks for your example. If you change EXIT SUB with END SUB then with GOSUB [DO SOMETHING] the target will fall beyond the scope of the SUB.
SUB FOO Varb1, Varb2, Varb3 'some code
GOSUB [DO.SOMETHING] 'more code
END SUB
[DO.SOMETHING] ' code RETURN
|
|
|
Post by Walt Decker on Jun 29, 2023 18:37:55 GMT -5
Correct.
I said provided it is within the SUB/FUNCTION code space. The target is no longer within that code space.
|
|
|
Post by Gordon Rahman on Jul 2, 2023 15:54:43 GMT -5
Thank you Mr. Rahman, It will take me a while to get my head around that one... Bedtime for me. Buttons create a button event There are four buttons in this listing. 3 of them are your buttons and one (the trapclose) is a windows button. Pressing a button generates a button-event with the button handle as parameter. You must place this parameter at your Event-sub. sub exitMM parameter1$ ... close #parameter1$ end sub At end sub the focus is returned to the caller!!! so in this case it is better to end the program before the end sub. Also module creates a button event too. sub module parameter2$ optionNumber = val(right$(parameter2$,1)) ... print "OPTION";optionNumber end sub To be complete ... mouse clicks generate a mouse event You must now place 3 three parameters at your Mouse-sub. The first one for the window or object in the window and the 2th and 3th parameters are the MouseX and MouseY of your mouse. At end sub the sub will return tpo the caller and will stop at the WAIT command. Gordon
|
|