Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Sun Nov 19, 2017 8:59 pm

All times are UTC - 7 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Nov 07, 2011 2:22 pm 
Offline

Joined: Thu Aug 09, 2007 4:44 pm
Posts: 67
I have 20 button objects on a screen, called "button_1" - "button_20" I would like a variable with a value of 1-20 to define which object will receive a change to a certain property. How would I write this in Qlarity code?

I want something like this:

button_(variable).value="new value"


Top
 Profile  
 
PostPosted: Mon Nov 07, 2011 2:27 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
This is probably the best way to do it.

Code:
'Global Code
dim buttons[] as buttonV2
'The empty is a placeholder because Qlarity arrays are zero based.  By putting empty in the first
'slot it ensures that buttons[1] == button_1
init buttons := [empty, button_1, button_2, button_3, ..., button_20]

func DoSomething(int index)
    buttons[index].value = "Some Value"
endfunc


This way will work as well and may be useful in other situations, but it is less efficient.
Code:
func DoSomething(int index)
    SetObjProp(GetObjRef("button_" + str(index)), "value", str("Some Value"))
endfunc

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Tue Nov 08, 2011 2:52 pm 
Offline

Joined: Thu Aug 09, 2007 4:44 pm
Posts: 67
Thanks jeremy, I used the first method you suggested. Is it possible to set a property of all objects in an array with one command, something like:

buttons[ALL].transparent=false


Top
 Profile  
 
PostPosted: Tue Nov 08, 2011 2:54 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Not directly. A for loop would cover it though
Code:
dim i as integer
for i = len(buttons)-1 to 0 step -1
    buttons[i].transparent = false
next

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group