APRES Posted September 18, 2006 Share Posted September 18, 2006 Is it possible to join multiple Case inside of GUI into loop? Example While 1 $msg = GUIGetMsg() Select Case $msg = $arrayitem[1] DoSomething(1) Case $msg = $arrayitem[2] DoSomething(2) Case $msg = $arrayitem[3] DoSomething(3) Case $msg = $arrayitem[4] DoSomething(4) ........................ Case $msg = $arrayitem[999] DoSomething(999) Case $msg = $arrayitem[1000] DoSomething(1000) So there is a temptation to do something like For $i=1 To 1000 Case $msg = $arrayitem[$i] DoSomething($i) Next I tried use Eval or Execute but didn't succeed. Is it possible to do? Thank! Link to comment Share on other sites More sharing options...
Developers Jos Posted September 18, 2006 Developers Share Posted September 18, 2006 (edited) Is it possible to join multiple Case inside of GUI into loop? I tried use Eval or Execute but didn't succeed. Is it possible to do? Thank!Why use a case? For $i=1 To 1000 if $msg = $arrayitem[$i] then DoSomething($i) ExitLoop endif Next EDIT: do you have 1000 GUI Controls"? Edited September 18, 2006 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
APRES Posted September 18, 2006 Author Share Posted September 18, 2006 Why use a case? For $i=1 To 1000 if $msg = $arrayitem[$i] then DoSomething($i) ExitLoop endif Next Don't know. Had read somewhere that "Case" is faster then "If...Then" But thanks anyhow. It works indeed. And the code became a lot shorter. do you have 1000 GUI Controls"?Of course not. It was just a shocking example Link to comment Share on other sites More sharing options...
shaamaan Posted April 26, 2007 Share Posted April 26, 2007 ... EDIT: do you have 1000 GUI Controls"? and what if i do have "1000" GUI controls? ...and i can not use other control: expandcollapse popup#include <GUIConstants.au3> GUICreate("My GUI menu", 300, 200) $menuLng = GUICtrlCreateMenu("Language") $item = "sk,cz,de" $item = StringSplit($item, ",") ; Create variables For $i = 1 To $item[0] $menuEntry = $item[0] Assign("item_" & $item[$i], GUICtrlCreateMenuitem($item[$i], $menuLng, $menuEntry, 1)) $menuEntry = $menuEntry - 1 Next GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit #cs --> this should be done in loop: Case $item_sk MsgBox(0, "", GUICtrlRead($item_sk, 1)) Case $item_cz MsgBox(0, "", GUICtrlRead($item_cz, 1)) Case $item_de MsgBox(0, "", GUICtrlRead($item_de, 1)) #ce EndSwitch WEnd Link to comment Share on other sites More sharing options...
Developers Jos Posted April 26, 2007 Developers Share Posted April 26, 2007 (edited) and what if i do have "1000" GUI controls? ...and i can not use other control:No idea what you mean by this statement.. But as far as your script: use an Array in stead of Assign command. That will allow you to loop through the defined number of controls. Try this example #include <GUIConstants.au3> GUICreate("My GUI menu", 300, 200) $menuLng = GUICtrlCreateMenu("Language") $item = "sk,cz,de" $item = StringSplit($item, ",") ; Create variables Dim $Controls[$item[0]] For $i = 1 To $item[0] $menuEntry = $item[$i] $Controls[$i-1] = GUICtrlCreateMenuItem($item[$i], $menuLng, $i -1, 1) Next GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch For $i = 0 To UBound($Controls)-1 If $msg = $Controls[$i] Then MsgBox(0, "", GUICtrlRead($Controls[$i], 1)) EndIf Next WEnd Edited April 26, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
shaamaan Posted April 26, 2007 Share Posted April 26, 2007 great! that is exactly what i wanted... many thanks! 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