|
- Forum - iziBasic
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257
Topic # 1559 |
Menu operation - What am I doing wrong? |
10/07/2007 @ 13:03 by Holger Laux
|
Hello iziBasic community,
I have a bit of a problem implementing correct menu operations. In short:
If I want to open a secondary custom form from the main program form, I could do that in two different ways:
1. Create a button that takes me to a subroutine. There, insert another "doevent" and if a Cancel button is pressed, the form is closed and I'll get back to the main form. This works perfectly fine.
2. If I do this with a menu item instead of a button, it does not work. With a bit of experimenting, I found that the program operation does not stay in the subroutine but switches immediately back to the main "doevent" loop. When the Cancel button is pressed, my program does not know what to do because the corresponding instruction is in the subroutine.
Please have a look at the following sample code to understand what I am trying to explain. You will need a resource file to actually compile it. If you un-comment the "print e" instruction, you will see the main doevent loop working.
Any ideas what I am doing wrong?
***sample code***
' Test1.ibas
'variables: 'e doevent on main form 'f menu item 'g doevent on second form
{CONSOLEFONT OFF} {CREATORID "Tes1"} {VERSION "1.0"} {MINOSVERSION "3.0"} {RESOURCEFILE "Test1.rsrc"} {PARSER OFF} {KEYEVENTS OFF} {SECUREFILES ON}
BEGIN MENU 100 BUTTON #1, "Second Form", 90,0,55,12 e=0 repeat e=doevents if e=1001 then f=menuitem if f=101 then gosub _secondform end if end if if e=1 then gosub _secondform end if 'print e until e=-1 end
_secondform: savescreen openform 200 g=0 repeat g=doevents if g=201 then closeform restorescreen end if until g>0 return
**** end sample code *** |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 1 -------- 11/07/2007 @ 14:39 by aldweb
visitor |
Hello Holger,
My guess (I just read your message, and did not test anything) is that your second subroutine does not take into account one case: when the user ticks on the menu, a 1001 event is triggered and your loop ends when g>0. Overall, any event will be with a positive value (except for few special events), so the execution will exit from this subroutine. Furthermore, checking only for g>0 is not very good, the application will not exit in case the user presses the Home button in the second form, and this is what he is used to and expects (unless you want him to really look at this window and take an action).
So, here is how I would write the 2nd subroutine (there are other alternatives, reusing the e variable for example, which is my favorite way of doing - but I will stick to using the g variable):
_secondform: savescreen openform 200 ' commented following line 'g=0 => not needed, doevents will return ' 0 if ever there is no event, ' same thing with e=0 in the ' first subroutine repeat g=doevents if g=201 then closeform restorescreen ' added following line g=-999 end if ' added following line if g=-1 let e=-1 ' program will ' exit smoothly until g<0 ' changed sign return
That should make it.
Cheers, aldweb
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 2 -------- 11/07/2007 @ 16:30 by Holger Laux
visitor |
Hello Aldweb,
Many thanks for your kind reply.
Your changes seem to work, but I do not quite understand why:
What is the difference between having an e=1 (button) and an e=1001 (menu) event? (The first one worked fine, the second one did not)
I tried to avoid reusing the e variable exactly for that reason: I did not want any old events being filtered through or being deleted too early.
The g>0 was intentional. I want the user to get back to the main form which is just one (cancel) click away.
I still have to figure out why g has to be negative, but if it works, I'll do it this way.
I have been tinkering with this (actually much larger) project for almost a year now and am still a long way off from going public.
Many thanks again,
Holger |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 3 -------- 12/07/2007 @ 00:03 by aldweb
visitor |
Hello Holger,
Other events may be triggered in your g event tracking loop. For instance, pen down, menu call, or title event, and so on... All these events will put a value >0 in g. So, your loop will stop and return to the main e event loop, and this is what you do not want.
Here is another way to write subroutine #2:
_secondform: savescreen openform 200 repeat g=doevents until g=201 closeform restorescreen return
Cheers, aldweb
|
|
|
topic active
topic closed
Sticky
New message -
Correct message
Close topic
Make sticky
|
|