Call gadget with variable?

Everything else that doesn't fall into one of the other PB categories.
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Call gadget with variable?

Post by vwidmer »

I have:

txtplgCoolBOX = TextGadget(#PB_Any, 0, 10, 100, 25, "plgCoolBOX", #PB_Text_Center)

I would like to do something like

SetGadgetText(Val("txt"+deviceName$),"CoolerBox")

this does not work..

how can I do something like this?

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
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Call gadget with variable?

Post by NicTheQuick »

This only works with Maps:

Code: Select all

NewMap gadgets.i()

gadgets("txtplgCoolBOX") = TextGadget(#PB_Any, 0, 10, 100, 25, "plgCoolBOX", #PB_Text_Center)

SetGadgetText(gadgets("txt" + deviceName$), "CoolerBox")
But why do you want this? Seems a bit odd to me.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Re: Call gadget with variable?

Post by vwidmer »

Thanks I will try.

I have a few containers that have text, button

I have a function that's pulling info from multiple urls and then need to populate the info above.

So I would like to just have a loop to do that without having to call each gadget.

Maybe there is a better way to do that?
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
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Call gadget with variable?

Post by HeX0R »

I still have no idea what you are going to do, but my proposal would be:
use Dialogs

Code: Select all

Procedure.s GetXMLString()
	Protected XML$

	XML$ + "<?xml version='1.0' encoding='UTF-16'?>"
	XML$ + ""
	XML$ + "<dialogs>"
	XML$ + "  <window name='win_main' flags='#PB_Window_SystemMenu' minwidth='200' xpos='407' ypos='541'>"
	XML$ + "    <vbox>"
	XML$ + "      <text name='txtplgCoolBOX' text='plgCoolBOX' flags='#PB_Text_Center'/>"
	XML$ + "    </vbox>"
	XML$ + "  </window>"
	XML$ + "</dialogs><!--DDesign0R Definition: PureBasic|1|1|0||-|0-->"

	ProcedureReturn XML$
EndProcedure


a$ = GetXMLString()
If ParseXML(0, a$) And XMLStatus(0) = #PB_XML_Success
	CreateDialog(0)
	OpenXMLDialog(0, 0, "win_main")
	deviceName$ = "plgCoolBOX"
	
	SetGadgetText(DialogGadget(0, "txt" + deviceName$), "CoolerBox")
	
	Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Call gadget with variable?

Post by Fred »

You can also use the Runtime operator for this:

Code: Select all

Define txtplgCoolBOX
Runtime txtplgCoolBOX

OpenWindow(0, 100, 100, 600, 400, "Test")

txtplgCoolBOX = TextGadget(#PB_Any, 0, 10, 100, 25, "plgCoolBOX", #PB_Text_Center)

SetGadgetText(GetRuntimeInteger("txtplgCoolBOX"), "CoolerBox")

Repeat  
  event = WaitWindowEvent()
Until Event= #PB_Event_CloseWindow
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Call gadget with variable?

Post by NicTheQuick »

Oh, right. I totally forget about the Runtime things. :oops:
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply