Ventura Posted August 27, 2014 Share Posted August 27, 2014 I want if I press the func1/func2 button it will show func 1 msg, then if I press again it will show func 2 msg.. and it continues.. as I know I can make a another button and make it work, but I want it to work with one button.. so I don't know where to put. #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 100, 60) $hButton_1 = GUICtrlCreateButton("Func1/Func2", 10, 10, 80, 40) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 _Func_1() EndSwitch WEnd Func _Func_1() MsgBox(1,"Func1","This is Func 1") EndFunc Func _Func_2() MsgBox(1,"Func2","This is Func 2") EndFunc Link to comment Share on other sites More sharing options...
Solution JohnOne Posted August 27, 2014 Solution Share Posted August 27, 2014 You can do it with a flag variable, here I used $Func1 #include <GUIConstantsEx.au3> Global $func1 = True $hGUI = GUICreate("Test", 100, 60) $hButton_1 = GUICtrlCreateButton("Func1/Func2", 10, 10, 80, 40) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 If $func1 Then _Func_1() Else _Func_2() EndIf $func1 = Not $func1 EndSwitch WEnd Func _Func_1() MsgBox(1, "Func1", "This is Func 1") EndFunc ;==>_Func_1 Func _Func_2() MsgBox(1, "Func2", "This is Func 2") EndFunc ;==>_Func_2 Ventura 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted August 27, 2014 Share Posted August 27, 2014 (edited) Johns way is probably way better, as a novice when I tried to do this I simply used a standard IF statement based on what I needed. As an example if I wanted a button to enable/disable the Windows firewall service the button only had 1 function but it would check to see the current status of the computer and perform the If statement thus giving me a result of 2 functions. If RegRead = (Firewall On) Then RegWrite (Turn Firewall Off) MsgBox Firewall Turned Off Else If RegRead (Firewall Off) Then RegWrite (Turn Firewall On) MsgBox Firewall Turned On (Not my actual script just an outline of what it was doing) Later I found that I can also call a simple If statement to see the current state and set the button text to the current status so before I click the button I know if its on/off. Worked for me but glad to know a new way. Edited August 27, 2014 by ViciousXUSMC Link to comment Share on other sites More sharing options...
Ventura Posted August 27, 2014 Author Share Posted August 27, 2014 That worked thanks Link to comment Share on other sites More sharing options...
JohnOne Posted August 27, 2014 Share Posted August 27, 2014 Ace AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Luigi Posted August 27, 2014 Share Posted August 27, 2014 (edited) I thinking some like this... expandcollapse popup#AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #Tidy_Parameters=/sf #include-once #include <Array.au3> #include <Misc.au3> #include <GUIConstantsEx.au3> OnAutoItExitRegister("_EXIT_BEFORE") Opt('GUIOnEventMode', 1) Opt('GUIEventOptions', 1) Opt('MustDeclareVars', 1) Opt('WinWaitDelay', 25) Global $aGuiSize[2] = [800, 600] Global $sGuiTitle = "GuiTitle" Global $hGui Global $hButton $hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1]) GUISetOnEvent($GUI_EVENT_CLOSE, '_EXIT') $hButton = GUICtrlCreateButton("Button [OFF]", 10, 10, 80, 20) GUICtrlSetOnEvent($hButton, "_HitButton") GUISetState(@SW_SHOW, $hGui) While Sleep(10) WEnd Func _EXIT() Exit EndFunc ;==>_EXIT Func _EXIT_BEFORE($sInput = 0) If IsDeclared("sInput") Then ConsoleWrite("_exit[ " & $sInput & " ]" & @LF) GUIDelete($hGui) EndFunc ;==>_EXIT_BEFORE Func _HitButton() Local Static $iHit = 0 If $iHit Then $iHit = 0 GUICtrlSetData($hButton, "Button [OFF]") SomeFunctionOFF() Else $iHit = 1 GUICtrlSetData($hButton, "Button [ON]") SomeFunctionON() EndIf EndFunc ;==>_HitButton Func SomeFunctionOFF() ConsoleWrite("SomeFunctionOFF()" & @LF) EndFunc ;==>SomeFunctionOFF Func SomeFunctionON() ConsoleWrite("SomeFunctionON()" & @LF) EndFunc ;==>SomeFunctionON Edited August 27, 2014 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 27, 2014 Moderators Share Posted August 27, 2014 Hi,Can I join in too? #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Func 1", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton Switch GUICtrlRead($cButton) Case "Func 1" _Func_1() GUICtrlSetData($cButton, "Func 2") Case "Func 2" _Func_2() GUICtrlSetData($cButton, "Func 1") EndSwitch EndSwitch WEnd Func _Func_1() MsgBox($MB_SYSTEMMODAL, "Func 1", "This is Func 1") EndFunc ;==>_Func_1 Func _Func_2() MsgBox($MB_SYSTEMMODAL, "Func 2", "This is Func 2") EndFunc ;==>_Func_2M23 MikahS 1 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...
Luigi Posted August 27, 2014 Share Posted August 27, 2014 @Melba, yes you can... but, my script is big! muaaaaaaaaaahahahahhah! Visit my repository Link to comment Share on other sites More sharing options...
JohnOne Posted August 27, 2014 Share Posted August 27, 2014 here's a beta version. #include <GUIConstantsEx.au3> Global $aFuncs[] $aFuncs[0] = _Func_1 $aFuncs[1] = _Func_2 Global $WhichFunc = 0 $hGUI = GUICreate("Test", 100, 60) $hButton_1 = GUICtrlCreateButton("Func1/Func2", 10, 10, 80, 40) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 $aFuncs[$WhichFunc] () $WhichFunc = Not $WhichFunc EndSwitch WEnd Func _Func_1() MsgBox(1, "Func1", "This is Func 1") EndFunc ;==>_Func_1 Func _Func_2() MsgBox(1, "Func2", "This is Func 2") EndFunc ;==>_Func_2 MikahS 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Luigi Posted August 27, 2014 Share Posted August 27, 2014 $WhichFunc = Not $WhichFunc I like this! Visit my repository Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted August 27, 2014 Share Posted August 27, 2014 I like this! Yeah that makes my brain hurt, Link to comment Share on other sites More sharing options...
MikahS Posted August 27, 2014 Share Posted August 27, 2014 @Melba23 GUI god over here.. 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...
JohnOne Posted August 27, 2014 Share Posted August 27, 2014 here's a beta version. #include <GUIConstantsEx.au3> Global $aFuncs[] $aFuncs[0] = _Func_1 $aFuncs[1] = _Func_2 Global $WhichFunc = 0 $hGUI = GUICreate("Test", 100, 60) $hButton_1 = GUICtrlCreateButton("Func1/Func2", 10, 10, 80, 40) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 $aFuncs[$WhichFunc] () $WhichFunc = Not $WhichFunc EndSwitch WEnd Func _Func_1() MsgBox(1, "Func1", "This is Func 1") EndFunc ;==>_Func_1 Func _Func_2() MsgBox(1, "Func2", "This is Func 2") EndFunc ;==>_Func_2 Actually this does not need beta version, just change Global $aFuncs[] To Global $aFuncs[2] AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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