Jump to content

Using a variable to define part of a GUI Contorl ID

Recommended Posts

Hello all,

I have some check boxes that I have defined as:

$CB_Descartes = GuiCtrlCreateCheckbox("Descartes", -1, 0)

$CB_Socrates = GuiCtrlCreateCheckbox("Socrates", -1, 0)

There are MANY more than this. At some point I have a series of If... Then statements to check the status of each box, and run a program :

If GUICtrlRead($CB_Descartes ) = $GUI_CHECKED then

RunWait(@ScriptDir & "\Installs\install Descartes")


If GUICtrlRead($CB_Socrates ) = $GUI_CHECKED then

RunWait(@ScriptDir & "\Installs\install Socrates")


I was hoping to simplify this to:

CheckRun("Descartes ")

CheckRun("Socrates ")

With a Function to do the If... Then part based on the passed string:


; CheckRun()


; See if the CheckBox associated with the passed application is checked

; If it is, run the passed application.


Func CheckRun($ApplicationName)

If GUICtrlRead( ["$CB_" & $ApplicationName]) = $GUI_CHECKED then

RunWait(@ScriptDir & "\Installs\install " & $ApplicationName)



Even better would be something that checks the status of all the checkboxes in the GUI and loops thru this for each. The Control ID for the checkboxes are all $CB_(ApplicationName), but the number of applications will grow and I was hoping to only have to add checkboxes for each without later paging thru all the If... Then statements. Also, the Application names are always consistently "Install (ApplicationName).exe"

Any insight on how better to reduce the required code for this?


Karl Sumwalt

Link to post
Share on other sites

Here's a link that might give another avenue for your problem


Loads the checkboxes from an ini

modify the keynames to be the titles, and the values to be the exes

SciTE for AutoItDirections for Submitting Standard UDFs


Don't argue with an idiot; people watching may not be able to tell the difference.


Link to post
Share on other sites

how about this

dim $checkbox_[100], $program_[100}

read programs in from ini file (into the array)

create gui

$checkbox_[1] = create check box

$checkbox_[2] = create check box

$checkbox_[3] = create check box

$checkbox_[4] = create check box

$checkbox_[5] = create check box

; and continue

; later

for $x = 1 to $checkbox_[0]

if $checkbox_[$x] = guichecked then $program_[$x] = "go"

;;;; or if $checkbox_[$x] = guichecked then RunWait($program_[$x])


if program_[1] = go then Run("the program1")

if program_[2] = go then Run("the program2")

just an idea


Edited by Valuater


Link to post
Share on other sites

I'd agree with Valuater. Using arrays to handle similar GUI Controls is a great way to go...Especially good for Radios, Checkboxes, and maybe some other controls...

1 For loop saves an infinite amount of variables and if statements ;)

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...