|
Post by bushrat on Jun 1, 2023 19:14:38 GMT -5
@ Rod, tsh73, xxgeek
Brilliant, brilliant, brilliant.
You have sorted out my problem, I am very grateful to you all.
I did omit in my previous post that I knew it was looping around matrix(42,2) but couldn't figure out exactly what was causing it. The code looked deceptively simple. Well that has saved me a lot of time. Thank you all again.
|
|
|
Post by bushrat on Jun 2, 2023 23:38:34 GMT -5
a quick follow up 'last post' on this matter.
Because I'm dealing with random nos. within a small range and require them all to have the same frequency(4) when the matrix is complete with no row duplicates - I've actually set up an occasional impossible target. I do not want to control which random nos. are generated along the way.
Suppose with a 42x2 matrix all except the last 2 rows are complete and further suppose that there is one random no. in the range which has never been generated up to that point, then the condition of no row duplicates in the remaining 2 rows can never be met, and the program will loop forever attempting to achieve the impossible.
The way around this is to have a running tally of the random nos, progressively eliminating from selection those which have reached their frequency limit, but this messes up both the randomness and the simplicity of the program - so I've modified the whole thing to allow for tail-end numbers to have row duplicates in the event of which I simply rerun the whole thing until tail-end duplicates don't occur. The program runs so quickly (surprisingly) that the extra time is not noticeable. Usually the very next run solves the problem.
That little problem took a lot longer to achieve than I would have believed, anyhow the problem's solved permanently now so I can just move on...
Thanks for again for your input.
|
|
|
Post by Rod on Jun 3, 2023 1:40:58 GMT -5
If these numbers are not truly random and are a fixed set of numbers at a fixed frequency it’s rather like a deck or decks of cards. In those circumstances the usual solution is to shuffle the numbers and not create them. There are examples of shuffling on the forum if you are not aware of the technique.
|
|
|
Post by bushrat on Jun 3, 2023 4:12:17 GMT -5
Hi, I'd prefer the nos. to be as hands-off random as possible. When I got into trouble I did consider using a no. pool and slotting the pool nos randomly into an array. Probably I'm just making life hard for myself and I didn't think about using an existing shuffling routine which for all intents and purposes is probably as random as the nos. need to be. Still, it was an unexpected challenge to get it right, it seemed so simple. It is simple really, just requires a bit of clear thinking and you guys were very helpful when I was getting frustrated at one point. Cheers.
|
|
|
Post by bushrat on Jun 25, 2023 19:04:36 GMT -5
After a long break I'm back looking at LB. The original random no. matrix problem I had is now fully resolved, thanks to assistance from mods etc. I'm now following up my debugger education, long neglected...
I'm using the 'step into' mode with no problem until I hit a 'wait' statement. I've tried all sorts of combinations of 'step into', 'step over', 'resume' etc. but just can't get past wait.
I'd be grateful for help with what I'm sure is a very elementary issue for debugger users. TIA
|
|
|
Post by Rod on Jun 26, 2023 1:52:53 GMT -5
What events have you set up to move away from the WAIT? If it is a keypress for example click on your program window and press a key, the debugger will follow the program flow to the key press handler you have coded. Another way to move through an interactive program with WAIT is to click on the left margin of the debugger window or the program window. Say at the start of the keypress handler. Now just run the program in the debugger and it will stop at the BREAK POINT you have set and let you single step from there.
|
|
|
Post by tsh73 on Jun 26, 2023 2:10:10 GMT -5
It kind of makes sence that then program goes to "wait" you cannot step more.
But you can catch it there it comes out of wait (in event handler) One way is to locate that place in debugger, select from menu Code | Run to line Then you make this event, it will stop an this line (and you can step more)
Another way is to set breakpoints You just click on left margin of debugger code window to set/clear breakpoints. (this way you can have more then one "catch points").
|
|
|
Post by tsh73 on Jun 26, 2023 2:13:09 GMT -5
Whoa! I never knew that.
|
|
|
Post by bushrat on Jun 26, 2023 3:31:43 GMT -5
Thank you all once again for your help. I'll try using break points as soon as I return to the debugger exercises I was doing.
Now I have a more pressing problem with correct GUI coding - if this problem is in the wrong topic section I apologise.
For a long time I have used a slab of code I copied from an example program given in LB to illustrate GUI implementation and it worked flawlessly. The thing is I just accepted it and never really understood it. So I decided once and for all to get to grips with GUI coding myself and not rely on something I never originally wrote. So I spent a good deal of time going through the tutorials to get a handle on it all. I thought I had mastered it but when I went to implement a GUI window for the first time...
I cannot believe I have spent ALL DAY messing around with this elementary GUI window (coding below). It's a simple window which offers 3 choices to the user about which 'module' to run. That's it - but I can't get it run correctly. If I fix one problem, a different problem crops up. If I don't get this right I'm going back to using input statements which I don't want to do. The coding below is version 1,567,823 of my attempts to get it right.
It should run so that 3 options are presented, the 'OK' button is pressed after selection, and the program resumes having hit the selected module.
'============ 'MENU OPTIONS '============ cls mainwin 600 400 UpperLeftX = 450 UpperLeftY = 150 WindowWidth = 480 WindowHeight = 430
statictext #p1, "MENU OPTIONS", 160, 30, 150, 20 statictext #p1, "============", 160, 50, 150, 20
radiobutton #p1.ext, " Option 1. Module 1", [optionOne], [nil], 60, 80, 400, 20
radiobutton #p1.ext, " Option 2. Module 2", [optionTwo], [nil], 60,110, 400, 20
radiobutton #p1.ext, " Option 3. Module 3", [optionThree], [nil], 60, 140, 400, 20
'button '------ button #p1.ok, "OK", [okClicked], UL, 270, 290, 90, 55
open " MAIN MENU" for window as #p1
'font '---- print #p1, "font Lucida_Console 8"
'trapclose event '--------------- print #p1, "trapclose [exitMM]"
[nil] close #p1.ext
[okClicked] wait
[optionOne] wait close #p1 goto [module1] [optionTwo] wait close #p1 goto [module2] [optionThree] wait close #p1 goto [module3]
goto [mainMenu]
[exitMM] close #p1 '================ 'END MENU OPTIONS '================
[module1] print print "you reached [module1]" end [module2] print print "you reached [module2]" end [module3] print print "you reached [module3]" end
|
|
|
Post by tsh73 on Jun 26, 2023 4:29:55 GMT -5
Right way is to start ne thread for each new problem. So other folks could use it / find it afterwards.
So you have 3 radiobuttons You do not do things on raduobutton selection But you need selection to be checked on button click.
!!! buttons should be recognisable from code !!! So they sould be named not #p1.ext but #p1.rb1 #p1.rb2 #p1.rb3
Now, you can check if radiobutton is set in code but it will need to check all three of them
Esay way (IMHO) - in "radibuttonSet" label save number of radiobutton to a variable then on button click use if..then goto[module] or use select case.
And I remove all code what unreachable (after "wait").
Have a look. Read the comments. Then in doubt, ask.
'============ 'MENU OPTIONS '============ cls 'mainwin 600 400 'this is in characters, so 600 400 does not make sence mainwin 80 25 UpperLeftX = 450 UpperLeftY = 150 WindowWidth = 480 WindowHeight = 430
statictext #p1, "MENU OPTIONS", 160, 30, 150, 20 statictext #p1, "============", 160, 50, 150, 20
radiobutton #p1.rb1, " Option 1. Module 1", [optionOne], [nil], 60, 80, 400, 20
radiobutton #p1.rb2, " Option 2. Module 2", [optionTwo], [nil], 60,110, 400, 20
radiobutton #p1.rb3, " Option 3. Module 3", [optionThree], [nil], 60, 140, 400, 20
'button '------ button #p1.ok, "OK", [okClicked], UL, 270, 290, 90, 55
open " MAIN MENU" for window as #p1
'font '---- print #p1, "font Lucida_Console 8"
'trapclose event '--------------- print #p1, "trapclose [exitMM]"
#p1.rb1, "set" 'by UI guidelines, one of radiobuttons should be preselected selected =1 'and we set our variable so program would know it
wait 'end of GUI setup code. Program goes to wait
[nil] 'do nothing here wait
[okClicked] close #p1 'close window if it not needed 'then select which module to run select case selected case 1 goto [module1] case 2 goto [module2] case 3 goto [module3] end select wait
[optionOne] selected =1 'in "radiobuttonSet" label save number of radiobutton to a variable wait
[optionTwo] selected =2 'all three wait
[optionThree] selected =3 wait
[exitMM] close #p1 print "window closed withot hitting OK" 'you might do something here 'end 'will it be the end? wait '================ 'END MENU OPTIONS '================
print "I should never get here" 'but without END or WAIT above I do end
[module1] print print "you reached [module1]" end [module2] print print "you reached [module2]" end [module3] print print "you reached [module3]" end
|
|
|
Post by Rod on Jun 26, 2023 4:31:36 GMT -5
Adding to Anatoly's advice I would also say you are using the wrong control, buttons are a better and simpler choice.
'============ 'MENU OPTIONS '============ mainwin 80 20 UpperLeftX = 450 UpperLeftY = 150 WindowWidth = 480 WindowHeight = 430
statictext #p1, "MENU OPTIONS", 160, 30, 150, 20 statictext #p2, "============", 160, 50, 150, 20 button #p1.b1, "Option 1", [module1], UL, 130, 90, 150, 20 button #p1.b2, "Option 2", [module2], UL, 130, 130, 150, 20 button #p1.b3, "Option 3", [module3], UL, 130, 170, 150, 20 open " MAIN MENU" for window as #p1
#p1 "trapclose [exitMM]" wait
[module1] print print "you reached [module1]" wait
[module2] print print "you reached [module2]" wait
[module3] print print "you reached [module3]" wait
[exitMM] print print "you exited the program" close #p1 end
|
|
|
Post by Rod on Jun 26, 2023 4:33:30 GMT -5
I would also get OUT of the habit of "PRINT #PL, command" use the more modern and simpler "#PL command" drop the PRINT and ,
|
|
|
Post by bushrat on Jun 26, 2023 7:03:54 GMT -5
Jeeze, you guys are good and very generous with your time. Thank you. Looks like I've got a bit to learn...
Funny thing is, the erroneous code I've been using for ages appears to work like a charm? but it had a sneaky effect with my latest program. I'm thinking it was the cause of my original problem - that I couldn't serially rerun the program because bits were still dangling off the GUI when I went to rerun it, so the first run was always OK but it crashed when I tried to repeat the run. (Actually, Rod hinted at this in a previous reply but I didn't know enough to recognise it.)
I've copied the code segments you've all given me and as soon as I can I'll report what happened.
Thank you all again.
|
|
|
Post by Gordon Rahman on Jun 26, 2023 7:30:18 GMT -5
And here is a modern way to program it.
'============ 'MENU OPTIONS '============ mainwin 80 20 UpperLeftX = 450 UpperLeftY = 150 WindowWidth = 480 WindowHeight = 430
statictext #p1, "MENU OPTIONS", 160, 30, 150, 20 statictext #p2, "============", 160, 50, 150, 20 button #p1.b1, "Option 1", module, UL, 130, 90, 150, 20 button #p1.b2, "Option 2", module, UL, 130, 130, 150, 20 button #p1.b3, "Option 3", module, UL, 130, 170, 150, 20
open " MAIN MENU" for window as #p1 #p1 "trapclose exitMM" wait
sub module h$ optionNumber = val(right$(h$,1)) print "OPTION";optionNumber end sub
sub exitMM h2$ print "you exited the program" close #h2$ end sub
|
|
|
Post by bushrat on Jun 26, 2023 9:25:23 GMT -5
Thank you Mr. Rahman, It will take me a while to get my head around that one...
Bedtime for me.
|
|