aldweb

Fermer I. aldweb

Fermer II. Gratuitiels PC

Fermer III. Gratuitiels Palm

Fermer IV. Partagiciels Palm

Fermer V. iziBasic Palm

Fermer VI. Connaissance Palm

Fermer VII. Ordinateur Poche

Fermer VIII. miniPortail

Spécial !



Version mobile
de l'aldweb Site

m.aldweb.com


Ni Français, ni Anglais ?

Essayez donc l'un de ces drapeaux :
[de] [es] [it] [pt]
Recherche




Météo / Spam / www

Météo Lyon


aldweb contre le SPAM


Newsletter
Pour avoir des nouvelles de ce site, inscrivez-vous à notre Newsletter.
S'abonner
Se désabonner
298 Abonnés
Sites web de la famille

Webmaster - Infos
News Amis
Visites

   visiteurs

   visiteurs en ligne

Sondage
Comment trouve-tu le nouvel habillage de l'aldweb Site ?
 
Superbe !
Joli
Moyen
Moche...
Résultats
forum.gifForum - iziBasic - Sujet n°1559

Forum - Forum
iziBasic - iziBasic


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

actif  Sujet n° 1559  Menu operation - What am I doing wrong?

le 10/07/2007 @ 13:03
par Holger Laux

Anonyme



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 ***
Ecrire à Holger Laux   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 1
--------
le 11/07/2007 @ 14:39
par aldweb

Anonyme

visiteur
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
Ecrire à aldweb   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 2
--------
le 11/07/2007 @ 16:30
par Holger Laux

Anonyme

visiteur
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
Ecrire à Holger Laux   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 3
--------
le 12/07/2007 @ 00:03
par aldweb

Anonyme

visiteur
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
Ecrire à aldweb   Poster une réponse  Haut
actif sujet actif   clos sujet clos   Important! Important!   Nouveau Nouveau message   -   Rectifier Rectifier message   Clôturer Clôturer sujet   Remonter Remonter
[]
Catégories de discussion  Forum 



 
^ Haut ^