aldweb

Close I. aldweb

Close II. PC Freeware

Close III. Palm Freeware

Close IV. Palm Shareware

Close V. iziBasic Palm

Close VI. Palm Knowledge

Close VII. Pocket Computer

Close VIII. miniPortail

Special !



Mobile version of
the aldweb Site

m.aldweb.com


Neither French, nor English?

Try one of these flags then:
[de] [es] [it] [pt]
Search




Weather / Spam / www

Lyon Weather


aldweb against spam


Newsletter
To receive news about this website, consider subscribing to our Newsletter.
Subscribe
Unsubscribe
298 Subscribers
Family's web sites

Webmaster - Infos
Friends News
Visits

   visitors

   visitors online

Poll
What do you think of the new design of the aldweb Site?
 
Great !
Beautiful
Average
So ugly...
Results
forum.gifForum - iziBasic - Topic #1559

Forum - Forum
iziBasic - iziBasic


Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257

active  Topic # 1559  Menu operation - What am I doing wrong?

10/07/2007 @ 13:03
by Holger Laux

Anonymous



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 ***
Write to Holger Laux   Post an answer  Top

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

Anonymous

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
Write to aldweb   Post an answer  Top

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

Anonymous

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
Write to Holger Laux   Post an answer  Top

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

Anonymous

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
Write to aldweb   Post an answer  Top
active topic active   closed topic closed   Sticky Sticky   New New message   -   Correct Correct message   Close Close topic   Make sticky Make sticky
[]
Forum Topic  Forum 



 
^ Top ^