GUI Adding Up/Down Buttons to a Counter Label

Get help with using AutoHotkey and its commands and hotkeys
Vaklev
Posts: 47
Joined: 04 Mar 2019, 13:58
GitHub: GeorgeSmete
Contact:

GUI Adding Up/Down Buttons to a Counter Label

Post by Vaklev » 16 May 2019, 09:40

Hi guys, first off, I am reading through the documentation but it's a bit confusing, are there any written guides for GUI's I can use? So I have a gui where it adds a +1 to a number, I use it as a report counter to log my reports at work to track stats. I am trying to add more buttons to it, such as a timer for time running since i launch the gui that updates every second, and a button that can change the existing report count (up and down) in case I log a report wrong. In addition I would also like a new tab that can log reports given the hour at which they were logged, example: total count between 9am-10am etc.

Code: Select all

^p::
Counter = 0000  ; Start counter at zero
Gui, Add, Text, vText, Completed Reports: %Counter%
Gui, Show, w220 h75, Report Counter  ; Show Gui
return

~^e::
loop
{
    sleep 200
    ImageSearch FoundX,FoundY, 345,300, 900,700, complete.png
    If ErrorLevel = 0
    break
}
Count:  ; Label
	Counter++  ; Increase counter by +1
	GuiControl,, Text, Completed Reports: %Counter%  ; Update Text control with new value
return


This is what I have so far, can someone please help me add the timer, buttons to change the report count number and perhaps a separate tab with tracking reports by the hour they were logged i.e when I hit my hotkey? Thanks in advance!

Edit:

I have added

Code: Select all

Gui, Add, UpDown, Completed Reports: %Counter% Range0-1000, 0
right after the text add but it completely gets rid of my "Completed reports" text but the button works, also the arrows are small, any way to make them bigger and work with my text?

Albireo
Posts: 1357
Joined: 16 Oct 2013, 13:53

Re: GUI NEED HELP WITH ADDING BUTTONS

Post by Albireo » 16 May 2019, 12:56

There were many quests on the same question ..
If you are lucky, someone will write the program for you ...
I can reason a little about three ways to make a timer.

1) The Sleep timer. (not so often useful).
This timer is not exactly precise, but the value is given in milliseconds.

Code: Select all

SplashTextOn 250, 75, TimerInfo, `nStart SleepTimer
FormatTime Time1, A_Now, HH:mm:ss
Sleep 3000
FormatTime Time2, A_Now, HH:mm:ss
SplashTextOff
MsgBox Time1 .: %Time1% `nTime2 .: %Time2%
ExitApp
2) The A_TickCount timer. (This is better)
The timer function becomes more precise and AHK instructions can occur during the waiting time.

Code: Select all

WaitTime = 3	; Seconds
StartTime := A_TickCount
SplashTextOn 250, 100, TimerInfo, `nRunning AHK-script `nA_TickCount
Loop
{	; Do what you want
	If ( A_TickCount > (StartTime + (WaitTime * 1000)))	; 3 sek = 3000ms
	{	Break
	}
}
SplashTextOff
MsgBox % "The AHK-program has ended after .: " A_TickCount - StartTime " milliseconds"
ExitApp
3) The SetTimer instruction. (This is another possibility)

Code: Select all

#Persistent
#SingleInstance force

WaitTime = 12	; Seconds
StartTime := A_TickCount
FormatTime StartTime1, %A_Now%, HH:mm:ss
; Progress b w380, `n`n`n`n, `n

SetTimer TestTimer, 250
Loop
{	; Do someting more?
	
	If ( A_TickCount > (StartTime + (WaitTime * 1000)))	; 3 sek = 3000ms
	{	Progress off
		SetTimer TestTimer, off
		MsgBox Now is the time (%WaitTime% sec) over! `n`nThis program ends!
		ExitApp
	}
}
Return


TestTimer:
	TimeNow := A_TickCount
	RunTime := ( TimeNow - StartTime ) / 1000
	TimeLeft := Round( WaitTime - RunTime ) ; in seconds
	;
	ClockEnd := A_Now
	ClockEnd += TimeLeft, Seconds	; To convert and calculate the end time in seconds
	FormatTime EndTime, %ClockEnd%, HH:mm:ss
	
	Percent := Round( ((RunTime / WaitTime) * 100) + 0.5, 0 )
	Progress %Percent%, % "StartTime1 .: " StartTime1 "`nEndTime . . .: " EndTime "`nTotal runtime .: " WaitTime " sec. `nTime left .: " TimeLeft " sec.", % "`nTest AHK - SetTimer!", TestTimer
Return
I do not know which method suits you best (Possibly example 2 or 3)

Post Reply

Return to “Ask For Help”