gadgets seem to work twice

Just starting out? Need help? Post your questions and find answers here.
MrCor
User
User
Posts: 22
Joined: Tue Dec 01, 2015 8:31 pm

gadgets seem to work twice

Post by MrCor »

Hi guys and dolls,

I am not an advanced programmer, so every now and then I get a simple problem that still seems to be too simple for me. And so... help.

I have written the following code:

Code: Select all

;- hoofdlus
Repeat

  Event = WaitWindowEvent(20)
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case 11 ; document geselecteerd
          Gosub SelectieGadget11
          
        Case 12 ; reset gadget 11 - documenten
          Gosub ResetGadget11
          
        Case 21 ; contact geselecteerd
          Gosub SelectieGadget21
          
        Case 22 ; reset gadget 21 - contacten
          Gosub ResetGadget21
          
        Case 23 ; zoeken contacten
          Gosub ZoekenContacten  
          
        Case 31 ; dossier geselecteerd
          Gosub SelectieGadget31
          
        Case 32 ; reset gadget 31 - dossiers
          Gosub ResetGadget31
          
        Case 33 ; zoeken dossiers
          Gosub ZoekenDossiers
          
        Case 41 ; omschrijving geselecteerd
          Gosub SelectieGadget41
          
        Case 42 ; reset gadget 41 - omschrijvingen
          Gosub ResetGadget41
          
        Case 43 ; zoeken omschrijving
          Gosub ZoekenOmschrijving
          
        Case 61 ; selectie bestanden in tmp
          Gosub SelectieGadget61
          
      EndSelect
    
  EndSelect

ForEver
Now so far there where no problems I noticed. But they was there all the time, I just had not noticed it.
I did notice it when in one of the subroutines something needed to be added. And there it was: the thing that had to be added, was added twice.
It looks as if the subroutine is executed twice... And no, nothing in the subroutine causes that.
So it looks as if this loop above executes the subroutine twice.

Is it a known problem? Don't think so, I must be doing something wrong, but what? Thanks in advance for your help and suggestions. I'm pretty shure it will be something simple I have overlooked.

Cheers, Cor



// Code Tags added (Kiffi)
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: gadgets seem to work twice

Post by mk-soft »

1. Gosub is not a good method (outdated, better to write and call procedures).
2. Missed depending on the gadget the function EventType() after gadget deliver different events. #PB_EventType_... See PB-Help of Gadget
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Mesa
Enthusiast
Enthusiast
Posts: 433
Joined: Fri Feb 24, 2012 10:19 am

Re: gadgets seem to work twice

Post by Mesa »

Yes, it's known if you don't use the EventType() function inside the loop, for some gadgets.

Do you still program the "spagghetti" way, with gosub/Return?

Code: Select all

Goto spaghetti

clic_spaghetti:
 Debug "clic spaghetti"
 Return
 
spaghetti:
If OpenWindow(0, 0, 0, 220, 100, "Exemple...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

    CanvasGadget(1, 10, 10, 200, 80)

   Repeat
     Event = WaitWindowEvent()
     
     Select Event
     
       Case #PB_Event_Gadget
         Select EventGadget()
           Case 1 
           	Debug "ho no, it triggers all the time !"
;            	Gosub clic_spaghetti
              Select EventType()
              	Case #PB_EventType_LeftClick
;               		Debug "clic"
              		Gosub clic_spaghetti
              EndSelect
              
         EndSelect
            
     EndSelect
   Until Event = #PB_Event_CloseWindow
 EndIf

M.
MrCor
User
User
Posts: 22
Joined: Tue Dec 01, 2015 8:31 pm

Re: gadgets seem to work twice

Post by MrCor »

Thanks for the suggestions, guys.

Using subs and returns... is that a technical or an ethical issue?
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: gadgets seem to work twice

Post by jacdelad »

MrCor wrote: Wed May 17, 2023 11:34 am Using subs and returns... is that a technical or an ethical issue?
Depends on whether you're ok with us hating you or not. :wink:
But seriously: Use procedures. Otherwise you will come to a point where noone knows why this or that piece of code is called. Also you can use "temporary" resources in procedures, they are freed when leaving the procedure.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
MrCor
User
User
Posts: 22
Joined: Tue Dec 01, 2015 8:31 pm

Re: gadgets seem to work twice

Post by MrCor »

I'm ok with you guys hating me... :wink:

You know, I am old-school. In the very past past I used to program in 3rd generation languages. Hard not to stick with what you know. That is, until things don't work out the way of those old-school things anymore.
I promise I will get familiar with procedures. Please don't hate me anymore :wink:
jacdelad wrote: Wed May 17, 2023 11:42 am
MrCor wrote: Wed May 17, 2023 11:34 am Using subs and returns... is that a technical or an ethical issue?
Depends on whether you're ok with us hating you or not. :wink:
But seriously: Use procedures. Otherwise you will come to a point where noone knows why this or that piece of code is called. Also you can use "temporary" resources in procedures, they are freed when leaving the procedure.
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: gadgets seem to work twice

Post by mk-soft »

We can reintroduce line numbers again. :mrgreen:
(Was great for jumps when you had inserted lines)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: gadgets seem to work twice

Post by jacdelad »

mk-soft wrote: Wed May 17, 2023 1:14 pm We can reintroduce line numbers again. :mrgreen:
(Was great for jumps when you had inserted lines)
Jesus...
I only 38, but I also remember line numbers and jumps. I guess I'm old too...
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply