ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

Simple Counter Utility Wanted

(1/3) > >>

AndyM:
Would someone please make me a simple Counter Program in AHK?

Two reasons:  I could use the utility and it would also serve well as an example of some of the AHK code I'd like to be more familiar with.  The GUI creation and counting subroutines would save me a lot of trial and error working the code out for myself.

There would be a simple small (~100 pixel tall x ~200 pixels wide) dialog box with:

   - Two buttons: Increment counter by 1, Decrement counter by 1.
   - Counter display (this could even be on one of the buttons)
  
The other feature would be that the counter would automatically increment by 1 each hour on the hour.  I could manually adjust the counter with the buttons for a start value, which would be incremented by 1 on the next hour (at the top of the hour, not an hour after I start).

That's all I'd need, but if you wanted to teach me one other thing, it would be to make the dialog box, buttons, counter, etc in different colors if this can be done in AHK.  You can pick the colors.

Thanks in advance to any takers!

Andy

skwire:
Here's a basic example (no colours):


--- Code: Autohotkey ---; -------------------; Set up environment. ; -------------------#NoEnv#SingleInstance, Force#PersistentSetBatchLines, -1SetControlDelay, -1DetectHiddenWindows, OnSetWorkingDir, %A_ScriptDir% ; -------------------------; Set any needed variables.; -------------------------myCounter := 0Allow_Counter_Update := True ; -------------; Build out GUI; -------------Gui, Margin, 3, 5Gui, Font, s30Gui, Add, Text  , xm     ym     w200 h100 0x1200 Center vCounter_txt          , % myCounterGui, FontGui, Add, Button, xm     ym+105 w95  h25                vPlus_btn    gOnButton, +1Gui, Add, Button, xm+105 ym+105 w95  h25                vMinus_btn   gOnButton, -1Gui, Show SetTimer, OnHour, 1000 ; Fire every second. Return ; End of auto-execute section.  GuiClose:GuiEscape:{    ExitApp}Return  OnButton:{    If ( A_GuiControl = "Plus_btn" )    {        DoCounter( "Up" )    }    Else If ( A_GuiControl = "Minus_btn" )    {        DoCounter( "Down" )    }}Return  OnHour:{    FormatTime, myNow, A_Now, HHmm    If ( Mod( myNow, 100 ) = 0 ) ; We're at the top of an hour.    {        If ( Allow_Counter_Update = True )        {            ; Increase counter by one and then don't allow any more            ; increases until the minute is up.  Otherwise, the            ; counter would increase by one every second.            DoCounter( "Up" )            Allow_Counter_Update := False        }    }        ; We are no longer in a top-of-the-hour minute so allow    ; updates again for the next top-of-the-hour minute.    If ( Mod( myNow, 100 ) != 0 )    {        Allow_Counter_Update := True    }}Return  DoCounter( sWay ){    Global        If ( sWay = "Up" )    {        myCounter++    }    Else If ( sWay = "Down" )    {        myCounter--    }    GuiControl, Text, Counter_txt, % myCounter}

AndyM:
Ah skwire, that's just perfect, exactly what I was looking for.  And the comments are quite helpful.

Thank you!!!   :Thmbsup:

Andy

skwire:
You're most welcome.  Glad I could help.   :)

skwire:
BTW, I just made a change to the code that I meant to make before I posted it.  Please refresh and re-grab the code.  Sorry about that.

Navigation

[0] Message Index

[#] Next page

Go to full version