antfuentes87 Posted May 7, 2015 Share Posted May 7, 2015 Hello everyone, hope you are having a great day. I have been trying to figure this out for awhile, but no luck yet so I thought I would ask for some help. Any help is much appreciated. I have a For Loop that creates GUICtrlCreateButton and adds them to array ($enclaveLessButtons). This works great, but the issue I am having now is working with the Switch statement and GUIGetMsg(). If I manual set the switch statement using $enclaveLessButtons[1], $enclaveLessButtons[2]. etc... it works. I can capture the button being clicked and perform whatever action I need. The thing is the array size of the $enclaveLessButtons can change at anytime and I really do not want to write every single Case statement for each variable in the array. How can I loop the Case statements using the $enclaveLessButtons array. The entire code is below, if you look at the While loop at the bottom, you can see a couple of Case examples I wrote out. This code will not run without other .au3 scripts I made that hold various functions, etc... Let me know if you have any questions and thank you for your time.expandcollapse popup#include "lib/load.au3" $enclaveURL = 'https://github.com/antfuentes87/enclave/tree/master/less' $enclaveResponseText = _HTTP_ResponseText($enclaveURL) $enclaveStartString = '<a href="' $enclaveEndString = '"' $enclaveStringInStr = 'blob' $enclaveFiles = _HTTP_ResponseTextStringBetweenArray($enclaveResponseText, $enclaveStartString, $enclaveEndString) $enclaveFiles = _Array_StringInStr($enclaveFiles, $enclaveStringInStr) Dim $enclaveLessButtons[1] Dim $enclaveLessContentArray[1] enclave() Func enclave() GUICreate("Enclave", 1400, 400) GUISetBkColor(0x00E0FFFF) GUISetFont(9, 300) GUICtrlCreateTab(0, 0, 1400, 300) For $enclaveFile In $enclaveFiles $enclaveFileUrl = $enclaveFile $enclaveFile = _StringExplode($enclaveFile, '/') $enclaveFileArraySize = UBound($enclaveFile)-1 $enclaveFile = $enclaveFile[$enclaveFileArraySize] If $enclaveFile <> 'enclave.less' And $enclaveFile <> 'vars.less' Then GUICtrlCreateTabItem($enclaveFile) $enclaveLessUrl = 'https://raw.githubusercontent.com' & $enclaveFileUrl $enclaveLessUrl = StringReplace($enclaveLessUrl, "blob/", "") $enclaveLessResponseText = _HTTP_ResponseText($enclaveLessUrl) $enclaveLessStartString = '.enc-' $enclaveLessEndString = ')' $enclaveLess = _HTTP_ResponseTextStringBetweenArray($enclaveLessResponseText, $enclaveLessStartString, $enclaveLessEndString) If IsArray($enclaveLess) Then $x = 10 $y = 26 For $enclaveLessContent In $enclaveLess $enclaveLessContentOrg = $enclaveLessContent $enclaveLessContent = _StringExplode($enclaveLessContent, "(") _ArrayAdd($enclaveLessButtons, GUICtrlCreateButton($enclaveLessContent[0], $x, $y, 200, 25)) _ArrayAdd($enclaveLessContentArray, $enclaveLessContentOrg) $y = $y + 26 Next EndIf EndIf Next GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) Local $idMsg While 1 Switch GUIGetMsg() Case $enclaveLessButtons[1] MsgBox(1, "Content", $enclaveLessContentArray[1]) Case $enclaveLessButtons[2] MsgBox(1, "Content", $enclaveLessContentArray[2]) Case $enclaveLessButtons[3] MsgBox(1, "Content", $enclaveLessContentArray[3]) Case $enclaveLessButtons[4] MsgBox(1, "Content", $enclaveLessContentArray[4]) Case $GUI_EVENT_CLOSE, $idClose ExitLoop EndSwitch WEnd EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 7, 2015 Moderators Share Posted May 7, 2015 antfuentes87,In future, posting runnable code would be a good idea if you require help - a short reproducer script is probably best.What I would normally do in the case of an indeterminate number of controls is to save their ControlIDs to an array and then loop through that array to check if GUIGetMsg has returned an event from one of them. Once you have the index of the control in the array you can easily arrange for other functions to run. Give me a moment and I will provide an example script.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MikahS Posted May 7, 2015 Share Posted May 7, 2015 Another solution that you could use is Dummy controls.Here is an example:GUICreate("test") Local $enclaveLessButtons[16], $x = 25, $y = 25 Local $iStart = GUICtrlCreateDummy() For $i = 1 To 15 Step 1 $enclaveLessButtons[$i] = GUICtrlCreateButton($i, $x, $y) $x += 25 $y += 25 Next Local $iEnd = GUICtrlCreateDummy() GUISetState() While 1 Switch GUIGetMsg() Case $iStart To $iEnd MsgBox(0, "", "hi") Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 7, 2015 Moderators Share Posted May 7, 2015 (edited) antfuentes87,Here you go:expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> While 1 $iCount = InputBox("How Many?", "Number of controls ( 1 To 5)") Switch $iCount Case "" Exit Case 1 To 5 ExitLoop EndSwitch WEnd Global $aButton[$iCount + 1] = [$iCount] $hGUI = GUICreate("Test", 500, 500) For $i = 1 To $iCount $aButton[$i] = GUICtrlCreateButton("Button " & $i, 10, ($i * 50) - 40, 80, 30) Next GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case Else For $i = 1 To $iCount If $iMsg = $aButton[$i] Then MsgBox($MB_SYSTEMMODAL, "Pressed", "Button " & $i) ExitLoop EndIf Next EndSwitch WEndPlease ask if you have any questions.M23 Edited May 7, 2015 by Melba23 Fixed code formatting Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
antfuentes87 Posted May 7, 2015 Author Share Posted May 7, 2015 (edited) Thank you both! I was able to come up with something from both of your examples. Thank you so much, on to the next task! If any of you guys like LESS, you can check out my LESS framework I am building @ https://github.com/antfuentes87/enclave This is what the AutoIt program is interacting with. Thanks again! Next time I will try to make a better example that works, it just has so many functions, I was unsure how I could include everything to make it work.expandcollapse popup#include "lib/load.au3" $enclaveURL = 'https://github.com/antfuentes87/enclave/tree/master/less' $enclaveResponseText = _HTTP_ResponseText($enclaveURL) $enclaveStartString = '<a href="' $enclaveEndString = '"' $enclaveStringInStr = 'blob' $enclaveFiles = _HTTP_ResponseTextStringBetweenArray($enclaveResponseText, $enclaveStartString, $enclaveEndString) $enclaveFiles = _Array_StringInStr($enclaveFiles, $enclaveStringInStr) Dim $enclaveLessButtons[1] Dim $enclaveLessContentArray[1] Dim $enclaveLessArray[1] enclave() Func enclave() GUICreate("Enclave", 1100, 600, -1, -1, $WS_BORDER, $WS_EX_TOPMOST) GUISetBkColor(0x00E0FFFF) GUISetFont(9, 300) GUICtrlCreateTab(0, 0, 1100, 600) For $enclaveFile In $enclaveFiles $enclaveFileUrl = $enclaveFile $enclaveFile = _StringExplode($enclaveFile, '/') $enclaveFileArraySize = UBound($enclaveFile)-1 $enclaveFile = $enclaveFile[$enclaveFileArraySize] If $enclaveFile <> 'enclave.less' And $enclaveFile <> 'vars.less' Then GUICtrlCreateTabItem($enclaveFile) $enclaveLessUrl = 'https://raw.githubusercontent.com' & $enclaveFileUrl $enclaveLessUrl = StringReplace($enclaveLessUrl, "blob/", "") $enclaveLessResponseText = _HTTP_ResponseText($enclaveLessUrl) $enclaveLessStartString = '.enc-' $enclaveLessEndString = ')' $enclaveLess = _HTTP_ResponseTextStringBetweenArray($enclaveLessResponseText, $enclaveLessStartString, $enclaveLessEndString) _ArrayAdd($enclaveLessArray, $enclaveLess) If IsArray($enclaveLess) Then $x = 10 $y = 26 If $enclaveFile = 'button.less' Then For $enclaveLessContent In $enclaveLess $enclaveLessContentOrg = $enclaveLessContent $enclaveLessContent = _StringExplode($enclaveLessContent, "(") If $enclaveLessContent[0] <> 'flex-auto' And $enclaveLessContent[0] <> 'create-border' And $enclaveLessContent[0] <> 'background-rgb' Then _ArrayAdd($enclaveLessButtons, GUICtrlCreateButton('enc-' & $enclaveLessContent[0], $x, $y, 200, 25)) _ArrayAdd($enclaveLessContentArray, $enclaveLessContentOrg) $y = $y + 26 EndIf Next Else For $enclaveLessContent In $enclaveLess $enclaveLessContentOrg = $enclaveLessContent $enclaveLessContent = _StringExplode($enclaveLessContent, "(") _ArrayAdd($enclaveLessButtons, GUICtrlCreateButton('enc-' & $enclaveLessContent[0], $x, $y, 200, 25)) _ArrayAdd($enclaveLessContentArray, $enclaveLessContentOrg) $y = $y + 26 Next EndIf EndIf EndIf Next $enclaveLessButtonsCount = UBound($enclaveLessButtons, 1) - 1 GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) While 1 $guiGetMsg = GUIGetMsg() Switch $guiGetMsg Case $GUI_EVENT_CLOSE ExitLoop Case Else For $i = 1 to $enclaveLessButtonsCount Step + 1 If $guiGetMsg = $enclaveLessButtons[$i] Then ;WinActivate("[CLASS:PX_WINDOW_CLASS]", "") ;Send('.enc-' & $enclaveLessContentArray[$i] & ');') ClipPut('.enc-' & $enclaveLessContentArray[$i] & ');') ExitLoop EndIf Next EndSwitch WEnd EndFunc Edited May 7, 2015 by antfuentes87 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