Gadget # counter?

Just starting out? Need help? Post your questions and find answers here.
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Gadget # counter?

Post by vwidmer »

I have some gadgets in a loop:

Code: Select all

SetGadgetColor(frmMain_txt_1,#PB_Gadget_FrontColor,#Black)
How can I set the 1 to change to 2..3..4 etc

example:

Code: Select all

For i = 1 To 10
  Debug i 
  SetGadgetColor(frmMain_txt_i,#PB_Gadget_FrontColor,#Black)  ??????
Next
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Gadget # counter?

Post by JHPJHP »

Removed; post ignored.
Last edited by JHPJHP on Sun Apr 18, 2021 2:30 am, edited 1 time in total.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Gadget # counter?

Post by RASHAD »

Hi
I presume you are using #PB_any

Code: Select all

Dim gad(10)
frmMain_txt_1 = TextGadget(#PB_Any,?,?,?,?,"")
gad(1) = frmMain_txt_1
frmMain_txt_2 = TextGadget(#PB_Any,?,?,?,?,"")
gad(2) = frmMain_txt_2
.
.
For g = 1 To 10
  SetGadgetColor(gad(g),#PB_Gadget_FrontColor, #Black)
Next
Egypt my love
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Re: Gadget # counter?

Post by vwidmer »

Yes I am using #PB_any it works the way you suggested. Thanks
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Gadget # counter?

Post by BarryG »

Building on Rashad's example, you can do it more conveniently like this:

Code: Select all

Global gadtotal
Global Dim gadnum(999)

Procedure AddGad(num)
  gadtotal+1
  gadnum(gadtotal)=num
EndProcedure

OpenWindow(0,300,300,130,110,"test",#PB_Window_SystemMenu)
AddGad(ButtonGadget(#PB_Any,10,10,100,25,"button 1"))
AddGad(ButtonGadget(#PB_Any,10,40,100,25,"button 2"))
AddGad(ButtonGadget(#PB_Any,10,70,100,25,"button 3"))

For g=1 To gadtotal
  DisableGadget(gadnum(g),1)
Next

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Gadget # counter?

Post by mk-soft »

If the gadget constants in the enumeration follow each other, it also works like this

Code: Select all

;-TOP

Enumeration Windows
  #Main
EndEnumeration

Enumeration Gadgets
  #TextGadget1
  #TextGadget2
  #TextGadget3
  #Button
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Procedure Main()
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 300, 200, "Window" , #MainStyle)
    
    TextGadget(#TextGadget1, 5, 5, 200, 25, "Text 1")
    TextGadget(#TextGadget2, 5, 35, 200, 25, "Text 2")
    TextGadget(#TextGadget3, 5, 65, 200, 25, "Text 3")
    ButtonGadget(#Button, 5, 95, 120, 25, "Set")
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #Button
              For i = #TextGadget1 To #TextGadget3
                SetGadgetColor(i, #PB_Gadget_FrontColor, #Red)
              Next
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Gadget # counter?

Post by RASHAD »

Hi JHPJHP
Your post didn't ignored
I think he responded to mine by mistake :D
I used to be ignored all the time :lol:
Take it easy fellow
Egypt my love
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Gadget # counter?

Post by JHPJHP »

Hi RASHAD,

That was me taking it easy :lol: I can't cut a break :) probably the perfect time for me to take one :wink:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Gadget # counter?

Post by RASHAD »

Hi JHPJHP
Good to see you getting younger again :)
Egypt my love
Post Reply