Jump to content
Sign in to follow this  
andybiochem

Creating labels in a FOR loop [SOLVED]

Recommended Posts

andybiochem

Hi!

I want to create a number of labels in a loop each with a handle based on the loop number. For example, say I wanted to do this:

$Label1 = GUICtrlCreateLabel("label1"......other data....)

$Label2 = GUICtrlCreateLabel("label2"......other data....)

$Label3 = GUICtrlCreateLabel("label3"......other data....)

.....

....

$Label49 = GUICtrlCreateLabel("label49"......other data....)

$Label50 = GUICtrlCreateLabel("label50"......other data....)

Could this be done more simply in a loop?

Something like this?:

For $i = 1 to 50

$Label & $i = GUICtrlCreateLabel("Label" & $i,.....other data.....)

Next

the bit in bold is creating a syntax error. What is the correct syntax for doing this?

Thank you in advance!

Edited by andybiochem

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites
d4rk

what's the error ? i see your script is ok, but i think the poin is , you also need to increase the posion of label (X,Y,top,right,left,...) so they won't be in the same place


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites
andybiochem

The error is the following:

C:\Documents and Settings\------\Desktop\test.au3(10,8) : ERROR: syntax error

$Label &

~~~~~~~^

C:\Documents and Settings\------\Desktop\test.au3 - 1 error(s), 0 warning(s)

I know I will need to alter left,top etc, I just need to know how to build the control handle based on the loop number.


- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites
d4rk

can you post full code here ? it's much easier to see


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites
andybiochem

Lol, ok...

GUICreate("",600,600)

For $i = 1 to 10

$Label & $i = GUICtrlCreateLabel("Label" & $i,50,$i * 50)

Next

...that's literally as far as I've got with this :) . Eventually I will want to use a loop like this to create 50+ labels, rather than having 50 GUICtrlCreateLabels messing up the script.

I've seen examples of this done using handles in an array, so that's an option, but I'd rather it was done more simply.


- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites
SxyfrG

For a start, you can't create variables like that. You'll need to use arrays (which you will find to be VERY handy once you become more experienced) which will hold the ID of each label.

So, instead of what you're trying to get working, i would suggest the following ...

GUICreate("",600,600)

Local $Label[11] ;Array subscripts start at 0, i.e. $Label[0], and because your while loop starts at 1, i've added an extra array subscript (correct me if my terminology is wrong)

For $i = 1 to 10

        $Label[$i] = GUICtrlCreateLabel("Label" & $i, 50, $i * 50)

Next

My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website

Share this post


Link to post
Share on other sites
andybiochem

For a start, you can't create variables like that. You'll need to use arrays (which you will find to be VERY handy once you become more experienced) which will hold the ID of each label.

Thanks for your reply, but I'd say my use of arrays was fairly good anyway....

http://www.autoitscript.com/forum/index.ph...st&p=526463

...although to be fair, I've not bothered with multiple dimensions yet.

I knew you could achieve this through use of an array, I just wondered if there was a way to manipulate variables as you would a string, i.e.

$i = Label

$ThisIsA & $i

gives... $ThisIsALabel

...but as you say, it looks like this can't be done.


- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites
SxyfrG

Wait, hold on ... just forgot an important function, Assign :)

Go look it up in the helpfile, it's exactly what you want :)


My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website

Share this post


Link to post
Share on other sites
andybiochem

Wait, hold on ... just forgot an important function, Assign :P

Go look it up in the helpfile, it's exactly what you want :)

w00t!!! :) That's the one!!! Thank you!

GUICreate("",600,600)

For $i = 1 to 10
Assign("Label" & $i,GUICtrlCreateLabel("Label" & $i,50,$i * 50))
Next

GUICtrlSetData($Label10,"10 - changed")

GUISetState(@SW_SHOW)
While 1
Sleep (100)
WEnd

unfortunately because the variables are not declared in the usual manner, AU3Check picks up any reference to them as 'undeclared', and we don't wanna be upsetting AU3Check now. :)

Oh well. I'm going with the array way of doing it.


- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

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  

×