Jewtus Posted August 19, 2015 Share Posted August 19, 2015 I'm trying to figure out a better way of triggering my stuff so I can clean up my case statements a bit.I have a list of menu options (pulled from a SQL query) that I want to build a menu and use that menu to trigger functions. I'm including an example:#include <GUIConstants.au3> $hGUI=GUICreate("View",50,50,50,50) ;Views $fmViews = GUICtrlCreateMenu("View") $fmAll = GUICtrlCreateMenuItem("All", $fmViews) GUICtrlCreateMenuItem("", $fmViews) local $aOptions[4][2]=[[1,'A'],[2,'B'],[3,'C'],[4,'D']] local $fmViewOptions[UBound($aOptions)] For $m=0 to UBound($aOptions) -1 $fmViewOptions[$m] = GUICtrlCreateMenuItem($aOptions[$m][1], $fmViews) Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($hGUI) ExitLoop Case $fmViewOptions ;~ Case $fmViewOptions[0],$fmViewOptions[1],$fmViewOptions[2],$fmViewOptions[3],$fmViewOptions[4] MsgBox(0,"","") EndSwitch WEndCan someone point me in the right direction? When I use $fmViewOptions as the case nothing happens, and when I list them all, I get constant pop up. What am I doing wrong? Link to comment Share on other sites More sharing options...
BrewManNH Posted August 19, 2015 Share Posted August 19, 2015 Try something like this.#include <GUIConstants.au3> $hGUI = GUICreate("View", 50, 50, 50, 50) ;Views $fmViews = GUICtrlCreateMenu("View") $fmAll = GUICtrlCreateMenuItem("All", $fmViews) GUICtrlCreateMenuItem("", $fmViews) Local $aOptions[4][2] = [[1, 'A'], [2, 'B'], [3, 'C'], [4, 'D']] Global $iUbound = UBound($aOptions) Local $fmViewOptions[$iUbound] For $m = 0 To $iUbound - 1 $fmViewOptions[$m] = GUICtrlCreateMenuItem($aOptions[$m][1], $fmViews) Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($hGUI) ExitLoop Case $fmViewOptions[0] To $fmViewOptions[$iUbound - 1] ;~ Case $fmViewOptions[0],$fmViewOptions[1],$fmViewOptions[2],$fmViewOptions[3],$fmViewOptions[4] MsgBox(0, "", "") EndSwitch WEnd If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
iamtheky Posted August 19, 2015 Share Posted August 19, 2015 (edited) and fun with $nMsg to find it in the original array, in case that's where you storing the actions for each item. I've only ever done it in this fashion when building controls in a loop, as I assume it would be all dicked up if scattered about.Case $fmViewOptions[0] to $fmViewOptions[ubound($fmViewOptions) - 1] msgbox(0, '' , $nMsg - ($fmViewOptions[0] - 1) & " , " & $aOptions[$nMsg - ($fmViewOptions[0])][1]) Edited August 19, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Jewtus Posted August 20, 2015 Author Share Posted August 20, 2015 (edited) @boththose that was what I was looking for. Edited August 20, 2015 by Jewtus 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