Jump to content
Sign in to follow this  
Kiti

GuiCtrlSetData in a loop

Recommended Posts

Kiti

Why I don't get a GUI with the word "something" written 5 times?

Edit: And, of course, what can I do to get what I want?

$Form1 = GUICreate("Form1", 224, 142, 338, 269)
$Label1 = GUICtrlCreateLabel("Label1", 44, 16, 36, 17)
$Label2 = GUICtrlCreateLabel("Label2", 44, 36, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 44, 56, 36, 17)
$Label4 = GUICtrlCreateLabel("Label4", 44, 76, 36, 17)
$Label5 = GUICtrlCreateLabel("Label5", 44, 96, 36, 17)

For $i = 1 to 5
    $string = "$Label" & $i
    Guictrlsetdata($string, "Something")
Next

GUISetState(@SW_SHOW)

While 1
    sleep(100)
WEnd

Thank you! muttley

Edited by Kiti

Share this post


Link to post
Share on other sites
cppman

I would recommend, however, that you put the labels in an array so you wouldn't need to call "Eval".

$Form1 = GUICreate("Form1", 224, 142, 338, 269)
$Label1 = GUICtrlCreateLabel("Label1", 44, 16, 36, 17)
$Label2 = GUICtrlCreateLabel("Label2", 44, 36, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 44, 56, 36, 17)
$Label4 = GUICtrlCreateLabel("Label4", 44, 76, 36, 17)
$Label5 = GUICtrlCreateLabel("Label5", 44, 96, 36, 17)

For $i = 1 to 5
    $string = "Label" & $i
    Guictrlsetdata(Eval($string), "something")
Next

GUISetState(@SW_SHOW)

While 1
    sleep(100)
WEnd
Edited by cppman

Share this post


Link to post
Share on other sites
Kiti

I would recommend, however, that you put the labels in an array so you wouldn't need to call "Eval".

$Form1 = GUICreate("Form1", 224, 142, 338, 269)
$Label1 = GUICtrlCreateLabel("Label1", 44, 16, 36, 17)
$Label2 = GUICtrlCreateLabel("Label2", 44, 36, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 44, 56, 36, 17)
$Label4 = GUICtrlCreateLabel("Label4", 44, 76, 36, 17)
$Label5 = GUICtrlCreateLabel("Label5", 44, 96, 36, 17)

For $i = 1 to 5
    $string = "Label" & $i
    Guictrlsetdata(Eval($string), "something")
Next

GUISetState(@SW_SHOW)

While 1
    sleep(100)
WEnd
That works perfect! Thank you so much!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×