What would be the easiest way to do this ..
I have a GUI with a button "Start". When I hit the start button, I do a ControlSetText command to change the button to "Stop".
Now, when I click that "Stop" button, how do I make it jump to the ButtonStop label? (and change the button text back to "Start")
My GUI is really small and have no room for seperate Start and Stop buttons.
Any help would be greatly appreciated!
Changing button text
Started by
Guest 100
, Jul 09 2007 05:35 AM
15 replies to this topic
#1
-
Posted 09 July 2007 - 05:35 AM
Here is a template. Please refer AHK doc for explanations.
Gui +ToolWindow Gui, Add, Button, w100 h25 g[color=red]StartStop[/color] v[color=red]ButtonText[/color], Start Gui, Show, , Test Return StartStop: GuiControlGet, ButtonText If ( ButtonText = "Start" ) { GuiControl,, ButtonText, Stop GoSub, Start } Else { GuiControl,, ButtonText, Start GoSub, Stop } Return Start: Return Stop: Return GuiClose: ExitApp
#2
-
Posted 09 July 2007 - 06:04 AM
Is this possible?
Have it goto the start label instead of "gosub". I want to run a bunch of commands there.
Thing is, when I hit the "stop" button, I want to stop whatever it's doing immediately (via the reload command).
Have it goto the start label instead of "gosub". I want to run a bunch of commands there.
Thing is, when I hit the "stop" button, I want to stop whatever it's doing immediately (via the reload command).
#4
-
Posted 09 July 2007 - 06:26 AM
Here is an example :
Is there any way to program in the stop button to do the "reload" command WITHOUT having to put code in my start loop?
The reason for that is I'm doing a lot of commands very fast and sometimes things are getting backed up .. there will be a delay if I add code in the loop to stop everything. SO If I do hit "stop" it may take 5-10 secs before anything is realized. I need this to be immedate.
Thanks!
WinSet, AlwaysOnTop, On, TestGUI GUI, Submit, NoHide GuiControlGet, ButtonText If ( ButtonText = "START" ) { GuiControl,, ButtonText, STOP Goto, Start } Else { GuiControl,, ButtonText, START Goto, Stop } Return Start: Loop, { envadd, count, 1 sleep, 100 } Stop: msgbox, %count%
Is there any way to program in the stop button to do the "reload" command WITHOUT having to put code in my start loop?
The reason for that is I'm doing a lot of commands very fast and sometimes things are getting backed up .. there will be a delay if I add code in the loop to stop everything. SO If I do hit "stop" it may take 5-10 secs before anything is realized. I need this to be immedate.
Thanks!
#5
-
Posted 09 July 2007 - 06:30 AM
when I hit the "stop" button, I want to stop whatever it's doing immediately (via the reload command).
Gui +ToolWindow Gui, Add, Button, w100 h25 gStartStop vButtonText, Start Gui, Add, StatusBar Gui, Show, , Test Return StartStop: GuiControlGet, ButtonText If ( ButtonText = "Start" ) { GuiControl,, ButtonText, Stop SetTimer, Start, -1 } Else Reload Return Start: Loop { Count ++ SB_SetText( "`t" Count ) Sleep 250 } Return GuiClose: ExitApp
:?: :!:
#6
-
Posted 09 July 2007 - 07:45 AM
Perfect! I modified it a litte bit though.
One last question .. is the "Reload" command the only way to reset everything back to normal?
Is there a way to stop everything (and change the button text back to "start") just like we first loaded the GUI?
So I can "start" and "stop" many times without having to reload the script?
Here is what I have :
One last question .. is the "Reload" command the only way to reset everything back to normal?
Is there a way to stop everything (and change the button text back to "start") just like we first loaded the GUI?
So I can "start" and "stop" many times without having to reload the script?
Here is what I have :
Gui, Add, Button, w100 h25 gStartStop vButtonText, Start Gui, Add, StatusBar Gui, Show, , Test Return StartStop: GuiControlGet, ButtonText If ( ButtonText = "Start" ) { GuiControl,, ButtonText, Stop SetTimer, Start, -1 return } Else MsgBox, %count% Reload Return Start: Loop { EnvAdd, count,1 } GuiClose: ExitApp
#7
-
Posted 09 July 2007 - 06:41 PM
untested
I have made a few different unrelated changes. you can put the counter loop back the way it was if you want, but there is no telling how much processor it was taking up.
Gui, Add, Text, w100 h25 vcountText, Press Start Gui, Add, Button, w100 h25 gStartStop vButtonText, Start Gui, Add, StatusBar Gui, Show, , Test Return StartStop: GuiControlGet, ButtonText If ( ButtonText = "Start" ) { GuiControl,, ButtonText, Stop SetTimer, counter, 1000 ;changed from -1 to make it count ~seconds } Else { GuiControl,, ButtonText, Start SetTimer, counter, off MsgBox, %count% count = 0 GuiControl,, countText, Press Start } Return counter: count++ GuiControl,, countText, %count% return GuiClose: ExitApp
I have made a few different unrelated changes. you can put the counter loop back the way it was if you want, but there is no telling how much processor it was taking up.
#8
-
Posted 09 July 2007 - 06:57 PM
Works great!
The only reason I did that Loop count was to use as much processor as possible. I wanted to test the "stop" button to make sure it was immediate under those conditions (which it does).
Thanks!
The only reason I did that Loop count was to use as much processor as possible. I wanted to test the "stop" button to make sure it was immediate under those conditions (which it does).
Thanks!
#9
-
Posted 09 July 2007 - 07:43 PM
why are you trying to use up processor?
#10
-
Posted 09 July 2007 - 07:55 PM
To make sure the "stop" button would still work under heavy conditions.
#11
-
Posted 09 July 2007 - 08:13 PM
Ran in to a weird problem ..
The code below runs fine the first time, but if I hit the stop button and then the start button again .. It completely skips the "Start" label and automatically goes to "Start1".
The code below runs fine the first time, but if I hit the stop button and then the start button again .. It completely skips the "Start" label and automatically goes to "Start1".
Gui, Add, Text, w100 h25 vcountText, Press Start Gui, Add, Button, w100 h25 gStartStop vButtonText, Start Gui, Add, StatusBar Gui, Show, , Test Return StartStop: GuiControlGet, ButtonText If ( ButtonText = "Start" ) { GuiControl,, ButtonText, Stop SetTimer, Start, 1000 } Else { GuiControl,, ButtonText, Start SetTimer, Start, off MsgBox, %count% count = 0 GuiControl,, countText, Press Start } Return Start: Msgbox, We are starting goto, Start1 Start1: Loop { EnvAdd, count, 1 } GuiClose: ExitApp
#12
-
Posted 09 July 2007 - 08:41 PM
you can remove the extra text I added, since you are not using it.
*untested
you also kept my settimer at 100, while looping the count, so it would start a new thread looping constantly...
Gui, Add, Text, w100 h25 vcountText, Press Start Gui, Add, Button, w100 h25 gStartStop vButtonText, Start Gui, Add, StatusBar Gui, Show, , Test Return StartStop: GuiControlGet, ButtonText If ( ButtonText = "Start" ) { GuiControl,, ButtonText, Stop SetTimer, Start, -1 } Else { GuiControl,, ButtonText, Start MsgBox, %count% count = 0 } Return Start: Msgbox, We are starting goto, Start1 return ;not needed, but I think it looks better Start1: Loop { ;EnvAdd, count, 1 count++ } GuiClose: ExitApp
*untested
you also kept my settimer at 100, while looping the count, so it would start a new thread looping constantly...
#13
-
Posted 09 July 2007 - 09:36 PM
Thanks for the speedy reply but yeah, I have already tried that and it still skips the "Start" routine when you start and stop multiple times.
If I use the "reload" command it works fine, but I was hoping that wasn't necessary.
If I use the "reload" command it works fine, but I was hoping that wasn't necessary.
#14
-
Posted 09 July 2007 - 09:40 PM
It's not that it skips right to the Start1 part, but that it never even Starts the Start routine the second time.
The Start1 loop is still running from the first time you started it, so the second time is on hold.
tested:
The Start1 loop is still running from the first time you started it, so the second time is on hold.
tested:
Gui, Add, Text, w100 h25 vcountText, Press Start Gui, Add, Button, w100 h25 gStartStop vButtonText, Start Gui, Add, StatusBar Gui, Show, , Test Return StartStop: GuiControlGet, ButtonText If ( ButtonText = "Start" ) { GuiControl,, ButtonText, Stop Break = 0 SetTimer, Start, -1 } Else { GuiControl,, ButtonText, Start MsgBox, %count% Break = 1 count = 0 } Return Start: Msgbox, We are starting goto, Start1 return ;not needed, but I think it looks better Start1: Loop { ;EnvAdd, count, 1 count++ If (Break = 1) Break } Return GuiClose: ExitApp
#15
-
Posted 09 July 2007 - 10:04 PM