KSum Posted September 30, 2005 Posted September 30, 2005 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") EndIf If GUICtrlRead($CB_Socrates ) = $GUI_CHECKED then RunWait(@ScriptDir & "\Installs\install Socrates") EndIf 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) EndIf EndFunc 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? Regards, Karl Sumwalt
GaryFrost Posted October 1, 2005 Posted October 1, 2005 Here's a link that might give another avenue for your problem http://www.autoitscript.com/forum/index.ph...indpost&p=71841 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.
Valuater Posted October 1, 2005 Posted October 1, 2005 (edited) 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]) next if program_[1] = go then Run("the program1") if program_[2] = go then Run("the program2") just an idea 8) Edited October 1, 2005 by Valuater
MSLx Fanboy Posted October 2, 2005 Posted October 2, 2005 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())
GaryFrost Posted October 2, 2005 Posted October 2, 2005 The link i posted loads the info from an ini into an array and then creates an array of controls SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
KSum Posted October 4, 2005 Author Posted October 4, 2005 Thank you all for the suggestion oif using an array, and the link to the previous forum item which I missed. I learned a lot and really do appreciate all the help on this forum. Karl
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now