Get name item definition (label) with a loop (for)

Hi all :)

A my friend asked me if is possible get a name of a label and change the label string with a loop. I have try this code:

rollout Test "test" width:100 height:200
(         
label temp1 "hello1"         
label temp2 "hello2"         
 
on Test open do         
(                  
for i=1 to 2 do                  
(            
local namelabel = "temp" + i as string                           
namelabel.text = "changetext" + i as string                  
)          
)
)
createDialog Test

I have always the same error : Unknown property: "text" in "temp1"

How to access the item definition (temp1/temp2) of label then update the value string ? I can do this?

Thanks for any help

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
victorgilbert's picture

Very nice explanation. I

Very nice explanation. I really got excited for the first look with the code. I use to write the similar kind of code in frequent times.

pixamoon's picture

`

hey again :)

just small thing:

You need to format it and execute it :)

(
try(destroyDialog ::Test)catch()
rollout Test "test" width:100 height:200
	(         
		label temp1 "hello1"         
		label temp2 "hello2"         
 
		on Test open do (                  
			for i=1 to 2 do                  
				(            
					local str = stringStream ""
					format "Test.temp%.text = \"%\" + % as string" i "changetext" i to:str     
					execute(str as string)
				)          
		)
	)
createDialog Test
)

It should works now,

Michele71's picture

Thanks pixamoon. I tried with

Thanks pixamoon. I tried with the format, but without execute it! hahahahah. I see if it works!

Thanks again for support and patience

pixamoon's picture

`

no prob, anytime :)

barigazy's picture

...

One more example

(
try(destroyDialog ::Test)catch()
rollout Test "test" width:200 height:100  
(         
		local lblNames = #("John", "Stalone", "BruceLee", "HELLOOOO", "ZZZZzzzz", "Michael", "71")
		label temp1 "hello1"  width:100 height:20 style_sunkenedge:on       
		label temp2 "hello2" width:100 height:20  style_sunkenedge:on        
 
		button btn "Random Names" width:150
		on btn pressed do for i = 1 to 2 do test.controls[i].caption = lblNames[random 1 lblNames.count]
)
createDialog Test
)

bga

Michele71's picture

Thanks for this good example

Thanks for this good example Barigazy! Thanks again :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.