BigDaddyO Posted June 28, 2005 Share Posted June 28, 2005 I have a GUI with 64 checkboxes and I want to be able to read each checkbox to determine which is checked and which is unchecked but I can't figure out how to do that in a loop. The variables don't seem to be able to be read as a variable... The Checkboxes are labled $CheckBox_1 through $CheckBox_64 $i = 1 Dim $Checked While $i <= 64 $Selected = GUICtrlRead($CheckBox_ & $i) if $Selected = 1 then $Checked = $Checked & "|" & $CheckBox_ & $i) $i = $i + 1 WEnd It fails when trying to do the GUICtrlRead because it does not understand the $CheckBox_ variable; but its supposed to be $CheckBox_# where # is the $i value How can I do this? Thanks, Mike Link to comment Share on other sites More sharing options...
JSThePatriot Posted June 28, 2005 Share Posted June 28, 2005 Your logic is a bit out of whack because of what you are trying to do. I understand what you are trying to do but your code doesnt. In your code you are trying to append $i to the end of the value of $CheckBox_ which obviously isnt a variable. Here is the solution... $i = 1 Dim $Checked, $CheckBox, $Selected While $i <= 64 $CheckBox = "$CheckBox_" & $i $Selected = GUICtrlRead($CheckBox) If $Selected = 1 Then $Checked = $Checked & "|" & $CheckBox $i = $i + 1 WEnd The above code is untested. Let me know if it works. It seems as though it might, but maybe not. I dont know that it can Return the value of a variable and then return the value of that all in one function. JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
blindwig Posted June 28, 2005 Share Posted June 28, 2005 I have written several scripts that do this (check a set of check boxes). I've always found the easiest way to do this is to keep the checkbox handles in an array instead of individual variables.Then, when you want to figure out which ones are checked, just loop through the array.see the source of my Selective Launch program as an example. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
JSThePatriot Posted June 28, 2005 Share Posted June 28, 2005 I have written several scripts that do this (check a set of check boxes). I've always found the easiest way to do this is to keep the checkbox handles in an array instead of individual variables.Then, when you want to figure out which ones are checked, just loop through the array.see the source of my Selective Launch program as an example.<{POST_SNAPBACK}>That was my first thought on this but I figured I would offer a solution that I didnt see as obvious . I would say the Array is the way to go for sure, but I would still like to know if my example worked at all.JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
FuryCell Posted June 28, 2005 Share Posted June 28, 2005 This might work. $i = 1 Dim $Checked While $i <= 64 $Selected = GUICtrlRead(Eval("CheckBox_" & $i)) if $Selected = 1 then $Checked = $Checked & "|" & "CheckBox_" & $i) $i = $i + 1 WEnd HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
BigDaddyO Posted June 28, 2005 Author Share Posted June 28, 2005 This might work.$i = 1 Dim $Checked While $i <= 64 $Selected = GUICtrlRead(Eval("CheckBox_" & $i)) if $Selected = 1 then $Checked = $Checked & "|" & "CheckBox_" & $i $i = $i + 1 WEnd<{POST_SNAPBACK}>COOL The Eval worked perfect. First time I ever used that command...Thanks,Mike Link to comment Share on other sites More sharing options...
FuryCell Posted June 28, 2005 Share Posted June 28, 2005 (edited) COOL The Eval worked perfect. First time I ever used that command...Thanks,Mike<{POST_SNAPBACK}>Your Welcome. P.S. Just wanted to tell you that if you are using the beta it would need to be changed to:$i = 1 Dim $Checked While $i <= 64 $Selected = GUICtrlRead(Eval("$CheckBox_" & $i)) if $Selected = 1 then $Checked = $Checked & "|" & "CheckBox_" & $i $i = $i + 1 WEnd Edited June 28, 2005 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
JSThePatriot Posted June 29, 2005 Share Posted June 29, 2005 Your Welcome. P.S. Just wanted to tell you that if you are using the beta it would need to be changed to:$i = 1 Dim $Checked While $i <= 64 $Selected = GUICtrlRead(Eval("$CheckBox_" & $i)) if $Selected = 1 then $Checked = $Checked & "|" & "CheckBox_" & $i $i = $i + 1 WEnd<{POST_SNAPBACK}>Ah the Eval function. I always wondered what that did, but never really read it . One thing though. I dont notice the difference between this post using beta and the other post.JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
FuryCell Posted June 29, 2005 Share Posted June 29, 2005 (edited) Ah the Eval function. I always wondered what that did, but never really read it . One thing though. I dont notice the difference between this post using beta and the other post.JS<{POST_SNAPBACK}>There is a $ sign next to the word CheckBox on line 5. Edited June 29, 2005 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
FuryCell Posted June 29, 2005 Share Posted June 29, 2005 Hey. just wanted to tell everybody who likes Eval() that they will also probably like Assign(). Using it you can assign a variable by string like: Assign("Message","Hello World") This would make the variable $Message eqal "Hello World". It becomes more useful in situations like this however. For $X=1 to 500 Assign("Random_" & $X,Random(1,100,1)) Next This would assign the variables $Var_1 , $Var_2 , $Var_3 etc all the way to $Var_500. that lets you reduce 500 lines of code into 3. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
JSThePatriot Posted June 29, 2005 Share Posted June 29, 2005 There is a $ sign next to the word CheckBox on line 5.<{POST_SNAPBACK}>lol... I looked over that thing so many times too.. Thanks for letting me know.Also about the Assign that is very nice.JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
blindwig Posted June 29, 2005 Share Posted June 29, 2005 Hey. just wanted to tell everybody who likes Eval() that they will also probably like Assign(). Using it you can assign a variable by string like:Assign("Message","Hello World")This would make the variable $Message eqal "Hello World".It becomes more useful in situations like this however.For $X=1 to 500 Assign("Random_" & $X,Random(1,100,1)) NextThis would assign the variables $Var_1 , $Var_2 , $Var_3 etc all the way to $Var_500. that lets you reduce 500 lines of code into 3. <{POST_SNAPBACK}>That's very slow however. It's much better (easier to use, and faster at runtime) to just use arrays. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
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