Input numbers and add them up:

Just starting out? Need help? Post your questions and find answers here.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: Input numbers and add them up:

Post by Oso »

Mindphazer wrote: Sat Oct 15, 2022 2:39 pm If you press Enter and the active gadget is #gad_number, or if you press the button (#gad-add) then you call AddNumber()
Thanks Mindphazer, I think the thing that confused me is that the below Select/Case, isn't specifically checking for the Enter key, but simply that #gad_number is tested as the active gadget for "whatever event" took place...

Code: Select all

  ev=WaitWindowEvent()
  If ev=#PB_Event_Menu
    Select GetActiveGadget()
      Case #gad_number,#gad_add : AddNumber()
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 472
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Input numbers and add them up:

Post by Mindphazer »

Well, in fact, i don't really understand this :

Code: Select all

Case #gad_number, #gad_add : AddNumber()
In my opinion, this should be enough :

Code: Select all

Case #gad_number : AddNumber()
No need to check #gad_add as it's the button gadget and it's not attached to a menu

But maybe BarryG can explain this point ?
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: Input numbers and add them up:

Post by Oso »

Mindphazer wrote: Sat Oct 15, 2022 4:55 pm In my opinion, this should be enough :

Code: Select all

Case #gad_number : AddNumber()
Yes, it seems to work fine with that amendment.
BarryG
Addict
Addict
Posts: 4206
Joined: Thu Apr 18, 2019 8:17 am

Re: Input numbers and add them up:

Post by BarryG »

Mindphazer wrote: Sat Oct 15, 2022 4:55 pm

Code: Select all

Case #gad_number, #gad_add : AddNumber()
This is so you can press Enter on the "Add number" button. If you remove the "#gad_add" bit, then you can't press Enter on it to add a number. I wanted my example to be fully working with keyboard as well as mouse.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: Input numbers and add them up:

Post by Oso »

BarryG wrote: Sun Oct 16, 2022 12:36 am This is so you can press Enter on the "Add number" button. If you remove the "#gad_add" bit, then you can't press Enter on it to add a number.
Yes, I see. There's quite a high attention to detail on this little example. It's good to find intentional keyboard support because reaching for the mouse is slow. Thanks for posting it Barry.
BarryG
Addict
Addict
Posts: 4206
Joined: Thu Apr 18, 2019 8:17 am

Re: Input numbers and add them up:

Post by BarryG »

Thanks, Oso.
Post Reply