marko001 Posted January 28, 2009 Share Posted January 28, 2009 Hi all mates, the program i'm developing uses lots of similar vars: if GUICtrlRead($enabled_Port1) = "1" then _status(6,"Port1 is Enabled") Sleep(150) if GUICtrlRead($enabled_Port2) = "1" then _status(6,"Port2 is Enabled") Sleep(150) if GUICtrlRead($enabled_Port3) = "1" then _status(6,"Port3 is Enabled") Sleep(150) if GUICtrlRead($enabled_Port4) = "1" then _status(6,"Port4 is Enabled") sleep(150) if GUICtrlRead($enabled_Port5) = "1" then _status(6,"Port5 is Enabled") Sleep(150) if GUICtrlRead($enabled_Port6) = "1" then _status(6,"Port6 is Enabled") Sleep(150) if GUICtrlRead($enabled_Port7) = "1" then _status(6,"Port7 is Enabled") Sleep(150) if GUICtrlRead($enabled_Port8) = "1" then _status(6,"Port8 is Enabled") Sleep(150) if GUICtrlRead($enabled_Port9) = "1" then _status(6,"Port9 is Enabled") Sleep(150) if GUICtrlRead($enabled_Port10) = "1" then _status(6,"Port10 is Enabled") and if $s_Port1Enabled = $GUI_CHECKED Then if $S_w1r1 = $GUI_CHECKED Then _status(6,"Port 1 Enabled and Message sent: " & $S_w1c1) ElseIf $S_w1r2 = $GUI_CHECKED Then _status(6,"Port 1 Enabled and Message sent: " & $S_w1c2) ElseIf $S_w1r3 = $GUI_CHECKED Then _status(6,"Port 1 Enabled and Message sent: " & $S_w1c3) ElseIf $S_w1r4 = $GUI_CHECKED Then _status(6,"Port 1 Enabled and Message sent: " & $S_w1c4) ElseIf $S_w1r5 = $GUI_CHECKED Then _status(6,"Port 1 Enabled and Message sent: " & $S_w1c5) ElseIf $S_w1r6 = $GUI_CHECKED Then _status(6,"Port 1 Enabled and Message sent: " & $S_w1c6) Else EndIf Else ... is it possible to use a FOR cycle, similar to for $i = 1 to 10 if guictrlread(eval($enabled_Port1) & $i) = "1" then _status(6,"....") next ? This doesn't solve me the problem so obviously something is missing... Is there a way to convert a string (i.e. ENABLED_PORT + $i) to a var $ENABLED_PORT1 ... $ENABLED_PORT10 ? Thanks everyone, mates, Marco Link to comment Share on other sites More sharing options...
Authenticity Posted January 28, 2009 Share Posted January 28, 2009 (edited) You can use array of controls and check all of them inside a for loop and send each in a row to a function that preform Select...Case or Switch Case. Edited January 28, 2009 by Authenticity Link to comment Share on other sites More sharing options...
Zedna Posted January 28, 2009 Share Posted January 28, 2009 (edited) eval() for $i = 1 to 10 if guictrlread(eval("enabled_Port" & $i)) = "1" then _status(6,"....") next Edited January 28, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
marko001 Posted January 28, 2009 Author Share Posted January 28, 2009 @Zedna: yeah, my fault, now it works. This solve some of my problems, but not all of them... in the Case i call this function: Case $PortCallButton _browseExe(GUICtrlRead($Instance)) func _browseExe($i) Select case $i = "1" $s_EXEFILE_1 = FileOpenDialog("Executable Filename ",@DesktopDir,"Exe (*.exe)") GUICtrlSetData($EXEFILE_1, $s_EXEFILE_1) case $i = "2" $s_EXEFILE_2 = FileOpenDialog("Executable Filename ",@DesktopDir,"Exe (*.exe)") GUICtrlSetData($EXEFILE_2, $s_EXEFILE_2) ... ... case $i = "9" $s_EXEFILE_9 = FileOpenDialog("Executable Filename ",@DesktopDir,"Exe (*.exe)") GUICtrlSetData($EXEFILE_9, $s_EXEFILE_9) case $i = "10" $s_EXEFILE_10 = FileOpenDialog("Executable Filename ",@DesktopDir,"Exe (*.exe)") GUICtrlSetData($EXEFILE_10, $s_EXEFILE_10) EndSelect EndFunc i tried to subst with: func _browseExe($i) eval("s_exefile_" & $i) = FileOpenDialog("Executable Filename ",@DesktopDir,"Exe (*.exe)") GUICtrlSetData(("exefile_" & $i), ("s_exefile_" & $i)) endfunc But it returns me error. Is there a way to simplify the code avoiding all that cases and doing something like you told me before? Thanks again, Marco Link to comment Share on other sites More sharing options...
Zedna Posted January 29, 2009 Share Posted January 29, 2009 func _browseExe($i) Assign("s_exefile_" & $i, FileOpenDialog("Executable Filename ",@DesktopDir,"Exe (*.exe)")) GUICtrlSetData(Eval("exefile_" & $i), Eval("s_exefile_" & $i)) endfunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Spiff59 Posted January 29, 2009 Share Posted January 29, 2009 (edited) I'm a little bored. And, I'm a little confused at the liberal use of the "eval" statement in this thread. If, for instance, you have a ton of checkbox controls defined for a range of ports, you could to do something like: expandcollapse popupGlobal $Checkbox_Port[64], $Port[64] GuiCreate("My Pgm", 600, 400) $left = 20 $top = 0 For $i = 0 to 63; Create an array of indexed checkboxes $top += 20 If $top > 320 Then $top = 20 $left += 80 EndIf $Checkbox_Port[$i] = GUICtrlCreateCheckbox("Port " & $i, $left, $top) Next GUISetState() While 1 WEnd ;------------------------------------------------------------------------- Func Scan_Checkboxes() For $i = 0 to 63; Scan all checkboxes $Port[$i] = GUICtrlRead($CheckBox_Port[$i]) Next EndFunc Func Process_Checkboxes() For $i = 0 to 63; Process all checkboxes If $Port[$i] Then Enable_Port($i) Else Disable_Port($i) EndIf Next EndFunc Func Enable_Port($i) ; Do the voodoo, that you do EndFunc Func Disable_Port($i) ; Undo the voodoo, that you dood EndFunc I'm willing to bet that commands like "eval", "assign" and "execute" are entirely resolved at run-time and should be avoided if you have a choice. Using arrays and subscripts is the standard practice, rather than creating a mass of unique variable names, then chopping those variable names up as strings and perfoming a slew of commands that aren't easily preprocessed/interpreted/compiled. Edited January 29, 2009 by Spiff59 Link to comment Share on other sites More sharing options...
marko001 Posted January 29, 2009 Author Share Posted January 29, 2009 (edited) @Spiff: thanks mate for your hint. That works fine to create/reading datas. But how to write to a setting file the values stored (i.e.) in the checkboxes to load it at beginning with a _loadsettings? I suppose i need to declare anyway the settings.ini vars (usually $s_...) and Iniwrite / Iniread them? Correct?? Edited January 29, 2009 by marko001 Link to comment Share on other sites More sharing options...
marko001 Posted January 29, 2009 Author Share Posted January 29, 2009 Anyone can please help me solve this? Thanks everyone, mates Link to comment Share on other sites More sharing options...
marko001 Posted January 29, 2009 Author Share Posted January 29, 2009 Bump Link to comment Share on other sites More sharing options...
marko001 Posted January 30, 2009 Author Share Posted January 30, 2009 bump Link to comment Share on other sites More sharing options...
BrettF Posted January 30, 2009 Share Posted January 30, 2009 Well it seems to me that you've already answered your own question.... Why don't you have a go first? Also, please don't bump your posts in a 24 hour period from your last post... Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! 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