Jump to content

Recommended Posts

Posted

Hi All,

Long time reader, first time poster......

This might be a daft question, then again maybe not.

I've a basic timer function (stop watch if you will) & I need to replicate this six times so all running independently, I'd wanted to achieve this have a small app with six tabs housing the independent timers however after creating two tabs i seem to be struggling.....

Before going any further I wondered whether this was even possible with tabs within a single gui?

I couldn't see anything within the help, if I have missed something apologies....

Any help or pointers would be greatly appreciated.

Many Thanks

Bob

  • Moderators
Posted

BobRoss,

Welcome to the AutoIt forum. :)

What you want sounds perfectly achievable - what code have you written so far? :huh:

M23

P.S. When you post code please use Code tags - put [autoit] before and [/autoit] after it - then you get a scrolling box and syntax colouring. ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

What do you have so far ?

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted (edited)

BobRoss,

Welcome to the AutoIt forum. :)

What you want sounds perfectly achievable - what code have you written so far? :huh:

M23

What do you have so far ?

Thanks for the replies.

This is the guts of the single timer, now all I did on the tab front was to create then I replicated the code with the addition of a number to note the corresponding tab - $btnStartPause2 as an example - I ended up with random times over lapping on each as opposed to running independently.

$frmMain = GUICreate("Single Stopwatch", 368, 125)
GUISetBkColor(0xFFFFFF)
$Logo = GUICtrlCreatePic("Small_N_White.jpg", 0, 80, 116, 36)
GUISetIcon("\\Images\Icons\_Logo_Clean.ico")
$GBElapsed = GUICtrlCreateGroup("Elapsed Time", 8, 12, 270, 65)
$lblTimer = GUICtrlCreateLabel("00:00:00.00", 60, 26, 200, 41)
GUICtrlSetFont(-1, 24, 400, 0, "Calibri")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$btnStartPause = GUICtrlCreateButton("&Start", 286, 17, 75, 25, 0)
$btnReset = GUICtrlCreateButton("&Reset", 285, 51, 75, 25, 0)

GUICtrlSetState($btnReset, $GUI_DISABLE)
GUISetState(@SW_SHOW)



Global $timer = 0, $aggregateTime = 0, $laptime = 0, $running = False
Dim $id, $oldId

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $btnStartPause
If GUICtrlRead($btnStartPause) == "&Start" Then
$timer = TimerInit()
SRandom(@SEC)
AdlibRegister("UpdateTimer")
GUICtrlSetData($btnStartPause, "&Pause")
GUICtrlSetState($btnReset, $GUI_DISABLE)
Else
AdlibUnRegister("UpdateTimer")

$aggregateTime += TimerDiff($timer)
GUICtrlSetData($lblTimer, _FormatTime($aggregateTime))
GUICtrlSetData($btnStartPause, "&Start")
GUICtrlSetState($btnReset, $GUI_ENABLE)
EndIf

Case $btnReset
$aggregateTime = 0
GUICtrlSetData($lblTimer, "00:00:00.00")
EndSwitch
WEnd

Func UpdateTimer()
Local $temp = _FormatTime(TimerDiff($timer) + $aggregateTime)

GUICtrlSetData($lblTimer, $temp)

EndFunc

Func _FormatTime($inputTime)
Local $time[4] = [0]

Local $originalTime = Round($inputTime / 1000, 2)

$time[0] = StringFormat("%.2d", Int($inputTime / 1000 / 60 / 60))

If $time[0] >= 1 Then
$inputTime -= Int($time[0] * 1000 * 60 * 60)
EndIf

$time[1] = StringFormat("%.2d", Int($inputTime / 1000 / 60))
If $time[1] >= 1 Then
$inputTime -= Int($time[1] * 1000 * 60)
EndIf

$time[2] = StringFormat("%.2d", Int($inputTime / 1000))
If $time[2] >= 1 Then
$inputTime -= Int($time[2] * 1000)
EndIf

$time[3] = StringFormat("%.2d", Int($inputTime / 10))

Return $time[0] & ":" & $time[1] & ":" & $time[2] & "." & $time[3]
EndFunc
Edited by BobRoss
  • Moderators
Posted

BobRoss,

You need to use arrays to get all the various timers separated. Here is a modified version of your script showing how you might do it: ;)

#include <GUIConstantsEx.au3>

Global $iTabCount = 3, $aTab[$iTabCount]
Global $aInitTimer[$iTabCount] = [-1, -1, -1], $aAggregateTime[$iTabCount] = [0, 0, 0]
Global $aTimerLabel[$iTabCount], $aStartPause[3], $aReset[$iTabCount]
Global $iAdlibCount = 0

$frmMain = GUICreate("Multiple Stopwatch", 370, 125)
GUISetBkColor(0xFFFFFF)
;$Logo = GUICtrlCreatePic("Small_N_White.jpg", 0, 80, 116, 36)
;GUISetIcon("\\Images\Icons\_Logo_Clean.ico")
$cTab = GUICtrlCreateTab(10, 10, 350, 100)

; Create tabs
For $i = 0 To $iTabCount - 1
    $aTab[$i] = GUICtrlCreateTabItem("Timer " & $i)
    $aTimerLabel[$i] = GUICtrlCreateLabel("00:00:00.00", 60, 50, 200, 40)
    GUICtrlSetFont(-1, 24, 400, 0, "Calibri")
    $aStartPause[$i] = GUICtrlCreateButton("&Start", 265, 40, 75, 25, 0)
    $aReset[$i] = GUICtrlCreateButton("&Reset", 265, 70, 75, 25, 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
Next

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            ; Was it a control?
            For $i = 0 To $iTabCount - 1
                If $nMsg = $aStartPause[$i] Then
                    ; It was a start/pause button
                    If GUICtrlRead($aStartPause[$i]) == "&Start" Then
                        $aInitTimer[$i] = TimerInit()
                        ; Start Adlib if required
                        If $iAdlibCount = 0 Then
                            AdlibRegister("UpdateTimer")
                        EndIf
                        ; Add to Adlib counter
                        $iAdlibCount += 1
                        ; Change button state
                        GUICtrlSetData($aStartPause[$i], "&Pause")
                        GUICtrlSetState($aReset[$i], $GUI_DISABLE)
                        ; No point in loopinp any further
                        ExitLoop
                    Else
                        ; Reduce Adlib count
                        $iAdlibCount -= 1
                        ; Unregister Adlib if not required
                        If $iAdlibCount = 0 Then
                            AdlibUnRegister("UpdateTimer")
                        EndIf
                        ; Set current time
                        $aAggregateTime[$i] += TimerDiff($aInitTimer[$i])
                        ; Set "Not timing" flag
                        $aInitTimer[$i] = -1
                        ; Set control state
                        GUICtrlSetData($aTimerLabel[$i], _FormatTime($aAggregateTime[$i]))
                        GUICtrlSetData($aStartPause[$i], "&Start")
                        GUICtrlSetState($aReset[$i], $GUI_ENABLE)
                        ; No point in loopinp any further
                        ExitLoop
                    EndIf
                ElseIf $nMsg = $aReset[$i] Then
                    ; Reset values and controls
                    $aAggregateTime[$i] = 0
                    GUICtrlSetData($aTimerLabel[$i], "00:00:00.00")
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

Func UpdateTimer()
    Local $sTemp
    For $i = 0 To $iTabCount - 1
        ; Check timer is running
        If $aInitTimer[$i] <> -1 Then
            $sTemp = _FormatTime(TimerDiff($aInitTimer[$i]) + $aAggregateTime[$i])
            GUICtrlSetData($aTimerLabel[$i], $sTemp)
        EndIf
    Next

EndFunc   ;==>UpdateTimer

Func _FormatTime($inputTime)
    Local $time[4] = [0]

    Local $originalTime = Round($inputTime / 1000, 2)

    $time[0] = StringFormat("%.2d", Int($inputTime / 1000 / 60 / 60))

    If $time[0] >= 1 Then
        $inputTime -= Int($time[0] * 1000 * 60 * 60)
    EndIf

    $time[1] = StringFormat("%.2d", Int($inputTime / 1000 / 60))
    If $time[1] >= 1 Then
        $inputTime -= Int($time[1] * 1000 * 60)
    EndIf

    $time[2] = StringFormat("%.2d", Int($inputTime / 1000))
    If $time[2] >= 1 Then
        $inputTime -= Int($time[2] * 1000)
    EndIf

    $time[3] = StringFormat("%.2d", Int($inputTime / 10))

    Return $time[0] & ":" & $time[1] & ":" & $time[2] & "." & $time[3]
EndFunc   ;==>_FormatTime

I hope the comments are sufficiently clear, but please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

BobRoss,

You need to use arrays to get all the various timers separated. Here is a modified version of your script showing how you might do it: ;)

#include <GUIConstantsEx.au3>

Global $iTabCount = 3, $aTab[$iTabCount]
Global $aInitTimer[$iTabCount] = [-1, -1, -1], $aAggregateTime[$iTabCount] = [0, 0, 0]
Global $aTimerLabel[$iTabCount], $aStartPause[3], $aReset[$iTabCount]
Global $iAdlibCount = 0

$frmMain = GUICreate("Multiple Stopwatch", 370, 125)
GUISetBkColor(0xFFFFFF)
;$Logo = GUICtrlCreatePic("Small_N_White.jpg", 0, 80, 116, 36)
;GUISetIcon("\\Images\Icons\_Logo_Clean.ico")
$cTab = GUICtrlCreateTab(10, 10, 350, 100)

; Create tabs
For $i = 0 To $iTabCount - 1
$aTab[$i] = GUICtrlCreateTabItem("Timer " & $i)
$aTimerLabel[$i] = GUICtrlCreateLabel("00:00:00.00", 60, 50, 200, 40)
GUICtrlSetFont(-1, 24, 400, 0, "Calibri")
$aStartPause[$i] = GUICtrlCreateButton("&Start", 265, 40, 75, 25, 0)
$aReset[$i] = GUICtrlCreateButton("&Reset", 265, 70, 75, 25, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
Next

GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case Else
; Was it a control?
For $i = 0 To $iTabCount - 1
If $nMsg = $aStartPause[$i] Then
; It was a start/pause button
If GUICtrlRead($aStartPause[$i]) == "&Start" Then
$aInitTimer[$i] = TimerInit()
; Start Adlib if required
If $iAdlibCount = 0 Then
AdlibRegister("UpdateTimer")
EndIf
; Add to Adlib counter
$iAdlibCount += 1
; Change button state
GUICtrlSetData($aStartPause[$i], "&Pause")
GUICtrlSetState($aReset[$i], $GUI_DISABLE)
; No point in loopinp any further
ExitLoop
Else
; Reduce Adlib count
$iAdlibCount -= 1
; Unregister Adlib if not required
If $iAdlibCount = 0 Then
AdlibUnRegister("UpdateTimer")
EndIf
; Set current time
$aAggregateTime[$i] += TimerDiff($aInitTimer[$i])
; Set "Not timing" flag
$aInitTimer[$i] = -1
; Set control state
GUICtrlSetData($aTimerLabel[$i], _FormatTime($aAggregateTime[$i]))
GUICtrlSetData($aStartPause[$i], "&Start")
GUICtrlSetState($aReset[$i], $GUI_ENABLE)
; No point in loopinp any further
ExitLoop
EndIf
ElseIf $nMsg = $aReset[$i] Then
; Reset values and controls
$aAggregateTime[$i] = 0
GUICtrlSetData($aTimerLabel[$i], "00:00:00.00")
ExitLoop
EndIf
Next
EndSwitch
WEnd

Func UpdateTimer()
Local $sTemp
For $i = 0 To $iTabCount - 1
; Check timer is running
If $aInitTimer[$i] <> -1 Then
$sTemp = _FormatTime(TimerDiff($aInitTimer[$i]) + $aAggregateTime[$i])
GUICtrlSetData($aTimerLabel[$i], $sTemp)
EndIf
Next

EndFunc ;==>UpdateTimer

Func _FormatTime($inputTime)
Local $time[4] = [0]

Local $originalTime = Round($inputTime / 1000, 2)

$time[0] = StringFormat("%.2d", Int($inputTime / 1000 / 60 / 60))

If $time[0] >= 1 Then
$inputTime -= Int($time[0] * 1000 * 60 * 60)
EndIf

$time[1] = StringFormat("%.2d", Int($inputTime / 1000 / 60))
If $time[1] >= 1 Then
$inputTime -= Int($time[1] * 1000 * 60)
EndIf

$time[2] = StringFormat("%.2d", Int($inputTime / 1000))
If $time[2] >= 1 Then
$inputTime -= Int($time[2] * 1000)
EndIf

$time[3] = StringFormat("%.2d", Int($inputTime / 10))

Return $time[0] & ":" & $time[1] & ":" & $time[2] & "." & $time[3]
EndFunc ;==>_FormatTime

I hope the comments are sufficiently clear, but please ask if you have any questions. :)

M23

You're a star mate, much appreciated.

I'll go off & have a play now I know which direction I need to be heading in, shall be a pleasant break from SQL coding later on this afternoon :shifty:

Cheers

Bob

Edited by BobRoss
  • 3 weeks later...
Posted

Hi All,

Everything works like a charm, so thanks again to M23.

I was wondering (I can't get my head around how this would be achieved nor did a post from anyone with the same query - Apologies if there are) would it be possible to give the 'end user' the ability to add whatever tab title? user defined?

Thanks

Bob

  • Moderators
Posted

BobRoss,

Of course you can rename the tabs - here is one way to do it (look for the <<<<<<<<<<< lines): :)

#include <GUIConstantsEx.au3>

Global $iTabCount = 3, $aTab[$iTabCount]
Global $aInitTimer[$iTabCount] = [-1, -1, -1], $aAggregateTime[$iTabCount] = [0, 0, 0]
Global $aTimerLabel[$iTabCount], $aStartPause[3], $aReset[$iTabCount]
Global $iAdlibCount = 0

$frmMain = GUICreate("Multiple Stopwatch", 370, 140)
GUISetBkColor(0xFFFFFF)
;$Logo = GUICtrlCreatePic("Small_N_White.jpg", 0, 80, 116, 36)
;GUISetIcon("\\Images\Icons\_Logo_Clean.ico")
$cTab = GUICtrlCreateTab(10, 10, 350, 100)

; Create tabs
For $i = 0 To $iTabCount - 1
    $aTab[$i] = GUICtrlCreateTabItem("Timer " & $i)
    $aTimerLabel[$i] = GUICtrlCreateLabel("00:00:00.00", 60, 50, 200, 40)
    GUICtrlSetFont(-1, 24, 400, 0, "Calibri")
    $aStartPause[$i] = GUICtrlCreateButton("&Start", 265, 40, 75, 25, 0)
    $aReset[$i] = GUICtrlCreateButton("&Reset", 265, 70, 75, 25, 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
Next
GUICtrlCreateTabItem("")

$cRename_Button = GUICtrlCreateButton("Rename Timer", 260, 115, 100, 20) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cRename_Button  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $iIndex = GUICtrlRead($cTab)
            $sNew_Name = InputBox("Rename Timer", "Enter the new name for the timer")
            If $sNew_Name Then
                GUICtrlSetData($aTab[$iIndex], $sNew_Name)
            EndIf
        Case Else
            ; Was it a control?
            For $i = 0 To $iTabCount - 1
                If $nMsg = $aStartPause[$i] Then
                    ; It was a start/pause button
                    If GUICtrlRead($aStartPause[$i]) == "&Start" Then
                        $aInitTimer[$i] = TimerInit()
                        ; Start Adlib if required
                        If $iAdlibCount = 0 Then
                            AdlibRegister("UpdateTimer")
                        EndIf
                        ; Add to Adlib counter
                        $iAdlibCount += 1
                        ; Change button state
                        GUICtrlSetData($aStartPause[$i], "&Pause")
                        GUICtrlSetState($aReset[$i], $GUI_DISABLE)
                        ; No point in loopinp any further
                        ExitLoop
                    Else
                        ; Reduce Adlib count
                        $iAdlibCount -= 1
                        ; Unregister Adlib if not required
                        If $iAdlibCount = 0 Then
                            AdlibUnRegister("UpdateTimer")
                        EndIf
                        ; Set current time
                        $aAggregateTime[$i] += TimerDiff($aInitTimer[$i])
                        ; Set "Not timing" flag
                        $aInitTimer[$i] = -1
                        ; Set control state
                        GUICtrlSetData($aTimerLabel[$i], _FormatTime($aAggregateTime[$i]))
                        GUICtrlSetData($aStartPause[$i], "&Start")
                        GUICtrlSetState($aReset[$i], $GUI_ENABLE)
                        ; No point in loopinp any further
                        ExitLoop
                    EndIf
                ElseIf $nMsg = $aReset[$i] Then
                    ; Reset values and controls
                    $aAggregateTime[$i] = 0
                    GUICtrlSetData($aTimerLabel[$i], "00:00:00.00")
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

Func UpdateTimer()
    Local $sTemp
    For $i = 0 To $iTabCount - 1
        ; Check timer is running
        If $aInitTimer[$i] <> -1 Then
            $sTemp = _FormatTime(TimerDiff($aInitTimer[$i]) + $aAggregateTime[$i])
            GUICtrlSetData($aTimerLabel[$i], $sTemp)
        EndIf
    Next

EndFunc   ;==>UpdateTimer

Func _FormatTime($inputTime)
    Local $time[4] = [0]

    Local $originalTime = Round($inputTime / 1000, 2)

    $time[0] = StringFormat("%.2d", Int($inputTime / 1000 / 60 / 60))

    If $time[0] >= 1 Then
        $inputTime -= Int($time[0] * 1000 * 60 * 60)
    EndIf

    $time[1] = StringFormat("%.2d", Int($inputTime / 1000 / 60))
    If $time[1] >= 1 Then
        $inputTime -= Int($time[1] * 1000 * 60)
    EndIf

    $time[2] = StringFormat("%.2d", Int($inputTime / 1000))
    If $time[2] >= 1 Then
        $inputTime -= Int($time[2] * 1000)
    EndIf

    $time[3] = StringFormat("%.2d", Int($inputTime / 10))

    Return $time[0] & ":" & $time[1] & ":" & $time[2] & "." & $time[3]
EndFunc   ;==>_FormatTime

Is that good enough or would you prefer another method such as a menu? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Is that good enough or would you prefer another method such as a menu? :huh:

M23

That's exactly what I was looking for, thanks M23 very much appreciated.

Cheers

Bob

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...