Jump to content

help! with dynamic variables


gcue
 Share

Recommended Posts

hello world!

i have an app that can spawn a stopwatch child window - works great! problem happens when i spawn multi stopwatch windows.. the challenge i think is because the same variable will appear for the childwindow ($stopwatch_child) and the label ($time) on this line (which updates the time count).

If $sTime <> $_time Then ControlSetText($stopwatch_child, "", $time, $_time)

any ideas how can i get around this?

Func StopWatch()
    
    $stopwatch_child = GUICreate("StopWatch", 150, 110, -1, -1, $WS_EX_MDICHILD)
    
    GUICtrlCreateLabel(GUICtrlRead($task_combo), 10, 5)

    $start_btn = GUICtrlCreateButton("START", 10, 30, 50, 20)
    GUICtrlSetOnEvent($start_btn, "Start_Time")
    
    $stop_btn = GUICtrlCreateButton("STOP", 70, 30, 50, 20)
    GUICtrlSetOnEvent($stop_btn, "Stop_Time")

    GUISetState()
    
EndFunc   ;==>StopWatch

Func Start_Time()
    
    $timer = TimerInit()
    AdlibEnable("Update_Time", 50)
    
    $time = GUICtrlCreateLabel("00:00:00", 10, 58)
    
EndFunc   ;==>Start_Time

Func Update_Time()
    
    _TicksToTime(Int(TimerDiff($timer)), $hour, $mins, $secs)
    Local $sTime = $_time ; save current time to be able to test and avoid flicker..
    $_time = StringFormat("%02i:%02i:%02i", $hour, $mins, $secs)
    If $sTime <> $_time Then ControlSetText($stopwatch_child, "", $time, $_time)
    
EndFunc   ;==>Update_Time
Link to comment
Share on other sites

hello world!

i have an app that can spawn a stopwatch child window - works great! problem happens when i spawn multi stopwatch windows.. the challenge i think is because the same variable will appear for the childwindow ($stopwatch_child) and the label ($time) on this line (which updates the time count).

any ideas how can i get around this?

Func StopWatch()
    
    $stopwatch_child = GUICreate("StopWatch", 150, 110, -1, -1, $WS_EX_MDICHILD)
    
    GUICtrlCreateLabel(GUICtrlRead($task_combo), 10, 5)

    $start_btn = GUICtrlCreateButton("START", 10, 30, 50, 20)
    GUICtrlSetOnEvent($start_btn, "Start_Time")
    
    $stop_btn = GUICtrlCreateButton("STOP", 70, 30, 50, 20)
    GUICtrlSetOnEvent($stop_btn, "Stop_Time")

    GUISetState()
    
EndFunc  ;==>StopWatch

Func Start_Time()
    
    $timer = TimerInit()
    AdlibEnable("Update_Time", 50)
    
    $time = GUICtrlCreateLabel("00:00:00", 10, 58)
    
EndFunc  ;==>Start_Time

Func Update_Time()
    
    _TicksToTime(Int(TimerDiff($timer)), $hour, $mins, $secs)
    Local $sTime = $_time; save current time to be able to test and avoid flicker..
    $_time = StringFormat("%02i:%02i:%02i", $hour, $mins, $secs)
    If $sTime <> $_time Then ControlSetText($stopwatch_child, "", $time, $_time)
    
EndFunc  ;==>Update_Time
The function that creates the GUI/etc. should be returning the handle. The point that calls that function should be saving the handle(s) in a Global array for use in referencing the different windows.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I believe he means something along the line of :

Func Main()
For $x = 1 to whenever
    $StopWatchCnt += 1
    $StopWatchArray[$StopWatchCnt] = StopWatch()
Next
EndFunc

Then adding this to the bottom of the StopWatch() function:

Return $stopwatch_child

Then you could use the values in the array to reference individual windows.

typo

Edited by Spiff59
Link to comment
Share on other sites

psalty,

the handle it returns, do you mean $stopwatch_child?

i already have that as a Global declaration.. hmm trying to figure out what u mean..

You have one global variable, but are creating multiple windows. That one variable can only hold the handle for one window. If you return that handle, then it can be kept in an array so they can all be manipulated as required:
Global $avStopWatches[1] = [0]

; Create a stop watch and add it to the array
_ArrayAdd($avStopWatches, StopWatch())


Func StopWatch()
    $stopwatch_child = GUICreate("StopWatch", 150, 110, -1, -1, $WS_EX_MDICHILD)
    
    ...rest of the function
    
    Return $stopwatch_child
EndFunc ;==>StopWatch

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

hmm its not working i still get the same behavior.. prob something i did wrong

1. i declared Global $avStopWatches[1] = [0]

2. wasnt sure where to do the _arrayadd

so i just put it outside of any function

3. i put the return where you told me.

here's the full script:

(appreciate your help PSalty!)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=stopwatch.ico
#AutoIt3Wrapper_Outfile=Time Tracker v0.1.exe
#AutoIt3Wrapper_Res_Fileversion=0.1.0.0
#AutoIt3Wrapper_Run_After="U:\scripts\Time Tracker\%scriptfile%"
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <file.au3>
#include <GuiComboBox.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <array.au3>
#include <GuiButton.au3>
#include <Timers.au3>
#include <Date.au3>

Opt("GUIOnEventMode", 1)

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent($exititem, "Xbutton")

TraySetState(1)

Global $tINI = (@ScriptDir & "\timetracker.ini"), $add_child, $OK_btn, $stopwatch_child, $time, $timer, $flag = 0
Global $tINItmp = (@ScriptDir & "\archive.txt"), $hour, $mins, $secs, $_time, $task_combo, $task_type, $PACS_ID
Global $manual_time, $time_combo, $avStopWatches[1] = [0]

_ArrayAdd($avStopWatches, StopWatch())

If Not FileExists($tINI) Then

    $text = '[TASK_TYPES]' & @CRLF
    $text &= 'Desktop Support=DSKSPT' & @CRLF
    $text &= 'General Admin=ADMIN-1' & @CRLF
    $text &= 'Mobile Support=MOBDEVSPT' & @CRLF
    $text &= 'PC Retire=KSSX' & @CRLF
    $text &= 'PC Setup=KSSX' & @CRLF
    $text &= 'Printer Support=PRNTSPT' & @CRLF
    $text &= 'Voice Support=VOICESPT' & @CRLF

    FileWrite($tINI, $text)

EndIf

GUICreate("Time Tracker", 415, 80); WS_EX_ACCEPTFILES

$filemenu = GUICtrlCreateMenu("&File")
$fileitem = GUICtrlCreateMenuItem("Open Archive", $filemenu)
GUICtrlSetOnEvent(-1, "OpenArchive")
$fileitem = GUICtrlCreateMenuItem("Exit", $filemenu)
GUICtrlSetOnEvent(-1, "Xbutton")


$task_combo = GUICtrlCreateCombo("Select Task Type...", 10, 5, 200, 20, $CBS_DROPDOWNLIST); create combobox and set first item
GUICtrlSetData(-1, LoadCombo(), "Select Task Type...")

$ADD_TYPE_btn = GUICtrlCreateButton("ADD", 10, 32, 20, 16, $BS_ICON)
GUICtrlSetImage($ADD_TYPE_btn, "dashboard.dll", 7)
GUICtrlSetOnEvent($ADD_TYPE_btn, "AddType_GUI")
GUICtrlSetTip($ADD_TYPE_btn, "Add Task Type")

$DEL_btn = GUICtrlCreateButton("DEL", 35, 32, 20, 16, $BS_ICON)
GUICtrlSetImage($DEL_btn, "dashboard.dll", 8)
GUICtrlSetOnEvent($DEL_btn, "DelType_GUI")
GUICtrlSetTip($DEL_btn, "Remove Task Type")

$manual_time = GUICtrlCreateInput(0, 220, 5, 40, 24)
GUICtrlSetTip($manual_time, "Enter Time Manually")

$p15_btn = GUICtrlCreateButton("", 265, 10, 14, 14, $BS_ICON)
GUICtrlSetImage($p15_btn, "dashboard.dll", 9)
GUICtrlSetOnEvent($p15_btn, "Plus15")
GUICtrlSetTip($p15_btn, "Add 15")

$m15_btn = GUICtrlCreateButton("", 285, 10, 14, 14, $BS_ICON)
GUICtrlSetImage($m15_btn, "dashboard.dll", 10)
GUICtrlSetOnEvent($m15_btn, "Minus15")
GUICtrlSetTip($m15_btn, "Minus 15")

$time_combo = GUICtrlCreateCombo("", 305, 5, 60, 20, $CBS_DROPDOWNLIST); create combobox and set first item
GUICtrlSetData(-1, "mins|hours", "mins") ; add other item snd set a new default

$ADD_TASK_btn = GUICtrlCreateButton("ADD", 375, 5, 24, 24, $BS_ICON)
GUICtrlSetImage($ADD_TASK_btn, "dashboard.dll", 7)
GUICtrlSetOnEvent($ADD_TASK_btn, "AddTask")
GUICtrlSetTip($ADD_TASK_btn, "Add Task")

$SW_btn = GUICtrlCreateButton("stopwatch", 270, 32, 65, 20)
GUICtrlSetOnEvent($SW_btn, "StopWatch")
GUICtrlSetTip($SW_btn, "Time Me")

$SMRY_btn = GUICtrlCreateButton("summary", 340, 32, 60, 20)
GUICtrlSetOnEvent($SMRY_btn, "Summary")
GUICtrlSetTip($SMRY_btn, "View Summary")

GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState()

Check_tINI()

While 1
    Sleep(1)
WEnd

Func Check_tINI()
    
    $aSectionNames = IniReadSectionNames($tINI)
    Dim $aSummary_Sections[1000][2]

    If @error Then
        MsgBox(64, "Summary", "No time entries have been entered.")
        Return
    Else
        For $i = 1 To $aSectionNames[0]
            If $aSectionNames[$i] = "TASK_TYPES" Then ContinueLoop

            If $i > 8 Then
                $copy = IniReadSection($tINI, $aSectionNames[2])
                IniWriteSection($tINItmp, $aSectionNames[2], $copy)
                
                IniDelete($tINI, $aSectionNames[2])
            EndIf
            
        Next
    EndIf

EndFunc   ;==>Check_tINI

Func LoadCombo()

    Local $arr = IniReadSection($tINI, "TASK_TYPES"), $sAssets
    If Not @error Then
        For $i = 1 To $arr[0][0]
            $sAssets &= $arr[$i][0] & "|"
        Next
        Return StringTrimRight($sAssets, 1)
    EndIf

    Return "Nothing loaded"

EndFunc   ;==>LoadCombo

Func Plus15()
    
    $new_val = GUICtrlRead($manual_time) + 15
    GUICtrlSetData($manual_time, $new_val)
    
EndFunc   ;==>Plus15

Func Minus15()
    
    If GUICtrlRead($manual_time) <> 0 Then
        $new_val = GUICtrlRead($manual_time) - 15
        GUICtrlSetData($manual_time, $new_val)
    EndIf
    
EndFunc   ;==>Minus15

Func AddType_GUI()

    $add_child = GUICreate("Add Task Type", 470, 100, -1, -1, $WS_EX_MDICHILD)

    GUICtrlCreateLabel("Task Type:", 10, 10)
    $task_type = GUICtrlCreateInput("", 10, 35, 230, 20, $ES_UPPERCASE)
    
    GUICtrlCreateLabel("PACS ID:", 260, 10)
    $PACS_ID = GUICtrlCreateInput("", 260, 35, 90, 20, $ES_UPPERCASE)
    
    $OK_btn = GUICtrlCreateButton("OK", 365, 35, 30, 20)
    GUICtrlSetOnEvent($OK_btn, "AddType")
    
    $CANCEL_btn = GUICtrlCreateButton("CANCEL", 400, 35, 60, 20)
    GUICtrlSetOnEvent($CANCEL_btn, "DEL_add_child")

    GUISetState()

EndFunc   ;==>AddType_GUI

Func DEL_add_child()
    GUIDelete($add_child)
EndFunc   ;==>DEL_add_child

Func AddType()

    If GUICtrlRead($task_type) = "" Then
        MsgBox(262144, "Add Task Type", "Please enter a Task Type.")
        Return
    EndIf

    If GUICtrlRead($PACS_ID) = "" Then
        MsgBox(262144, "Add Task Type", "Please enter a PACS ID.")
        Return
    EndIf
    
    $search = IniRead($tINI, "TASK_TYPES", GUICtrlRead($task_type), "NOT_FOUND")
    If $search <> "NOT_FOUND" Then
        MsgBox(262144, "Add Task Type", "That Task Type already exists, please choose another.")
        GUISwitch($add_child)
        GUICtrlSetData($task_type, "")
        Return
    EndIf

    IniWrite($tINI, "TASK_TYPES", GUICtrlRead($task_type), GUICtrlRead($PACS_ID))
    
    $entries = ("TASK_TYPES")
    $entries_temp = ($entries & "_TEMP")

    $sort = IniReadSection($tINI, $entries)
    
    _ArraySort($sort, 0, 1)

    IniWriteSection($tINI, $entries_temp, $sort)
    IniDelete($tINI, $entries)
    IniRenameSection($tINI, $entries_temp, $entries)
    
    GUICtrlSetData($task_combo, "")
    GUICtrlSetData($task_combo, "" & LoadCombo(), GUICtrlRead($task_type))

    GUIDelete($add_child)

EndFunc   ;==>AddType

Func DelType_GUI()
    
    $current_selection = GUICtrlRead($task_combo)
    If $current_selection = "Select Task Type..." Then
        MsgBox(262144, "Remove Task Type", "Please select a Task Type first.")
        Return
    EndIf
    
    $del_confirm = MsgBox(262180, "Remove Task Type", "Are you sure you want to remove " & GUICtrlRead($task_combo) & "?")
    
    If $del_confirm = 6 Then
        IniDelete($tINI, "TASK_TYPES", GUICtrlRead($task_combo))
        
        $entries = ("TASK_TYPES")
        $entries_temp = ($entries & "_TEMP")

        $sort = IniReadSection($tINI, $entries)
        
        _ArraySort($sort, 0, 1)

        IniWriteSection($tINI, $entries_temp, $sort)
        IniDelete($tINI, $entries)
        IniRenameSection($tINI, $entries_temp, $entries)
        
        GUICtrlSetData($task_combo, "")
        GUICtrlSetData($task_combo, "" & LoadCombo(), "Select Task Type...")
    EndIf

    If $del_confirm = 7 Then
        Return
    EndIf
    
EndFunc   ;==>DelType_GUI

Func StopWatch()
    
    $current_selection = GUICtrlRead($task_combo)
    If $current_selection = "Select Task Type..." Or $current_selection = "" Then
        MsgBox(262144, "StopWatch", "Please select a Task Type first.")
        Return
    EndIf
    
    If WinExists("StopWatch", GUICtrlRead($task_combo)) Then
        MsgBox(262144, "StopWarch", "There is already a StopWatch for " & GUICtrlRead($task_combo))
        Return
    EndIf
    
    $stopwatch_child = GUICreate("StopWatch", 150, 110, -1, -1, $WS_EX_MDICHILD)
    
    GUICtrlCreateLabel(GUICtrlRead($task_combo), 10, 5)

    $start_btn = GUICtrlCreateButton("START", 10, 30, 50, 20)
    GUICtrlSetOnEvent($start_btn, "Start_Time")
    
    $stop_btn = GUICtrlCreateButton("STOP", 70, 30, 50, 20)
    GUICtrlSetOnEvent($stop_btn, "Stop_Time")

    GUISetState()
    
    Return $stopwatch_child
    
EndFunc   ;==>StopWatch

Func Start_Time()
    
    $flag = 1
    
    $timer = TimerInit()
    AdlibEnable("Update_Time", 50)
    
    $time = GUICtrlCreateLabel("00:00:00", 10, 58)
    
EndFunc   ;==>Start_Time

Func Stop_Time()
    
    If $flag = 0 Then
        MsgBox(262144, "StopWatch", "You have to START the timer first.")
        Return
    EndIf
    
    $count = $_time
    
    $add_confirm = MsgBox(262180, "StopWatch", "Are you sure you want to add " & $_time & " to " & GUICtrlRead($task_combo) & "?")

    If $add_confirm = 6 Then
        IniReadSection($tINI, @MON & "/" & @MDAY & "/" & @YEAR)
        If @error Then
            $sLongDayName = _DateDayOfWeek(@WDAY)
            $sLongMonthName = _DateToMonth(@MON)
            IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $sLongDayName & ", " & $sLongMonthName & " " & @MDAY & ", " & @YEAR, "-")
        EndIf
        
        $prev_time = IniRead($tINI, @MON & "/" & @MDAY & "/" & @YEAR, GUICtrlRead($task_combo), "00:00:00")
        
        $duration = AddTime($count, $prev_time)
        
        IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, GUICtrlRead($task_combo), $duration)
    EndIf
    
    $flag = 0
    
    GUICtrlSetData($task_combo, "")
    GUICtrlSetData($task_combo, "" & LoadCombo(), "Select Task Type...")
    
    GUIDelete($stopwatch_child)
    
EndFunc   ;==>Stop_Time

Func AddTime($TIME1, $TIME2)
    
    Local $MIN_CARRY = 0, $HOUR_CARRY = 0
    $SPLIT1 = StringSplit($TIME1, ":")
    $SPLIT2 = StringSplit($TIME2, ":")
    $SEC = Number($SPLIT1[3]) + Number($SPLIT2[3])
    While $SEC >= 60
        $SEC -= 60
        $MIN_CARRY += 1
    WEnd
    $MIN = Number($SPLIT1[2]) + Number($SPLIT2[2])
    $MIN += $MIN_CARRY
    While $MIN >= 60
        $MIN -= 60
        $HOUR_CARRY += 1
    WEnd
    $hour = Number($SPLIT1[1]) + Number($SPLIT2[1])
    $hour += $HOUR_CARRY
    If $hour >= 24 Then
        Return "ERROR"
    Else
        $hour = String($hour)
        $MIN = String($MIN)
        $SEC = String($SEC)
        If StringLen($hour) < 2 Then $hour = "0" & $hour
        If StringLen($MIN) < 2 Then $MIN = "0" & $MIN
        If StringLen($SEC) < 2 Then $SEC = "0" & $SEC
        Return $hour & ":" & $MIN & ":" & $SEC
    EndIf
    
EndFunc   ;==>AddTime

Func Update_Time()
    
    _TicksToTime(Int(TimerDiff($timer)), $hour, $mins, $secs)
    Local $sTime = $_time ; save current time to be able to test and avoid flicker..
    $_time = StringFormat("%02i:%02i:%02i", $hour, $mins, $secs)
    If $sTime <> $_time Then ControlSetText($stopwatch_child, "", $time, $_time)
    
EndFunc   ;==>Update_Time

Func AddTask()
    
    $current_selection = GUICtrlRead($task_combo)
    If $current_selection = "Select Task Type..." Or $current_selection = "" Then
        MsgBox(262144, "Add Task", "Please select a Task Type first.")
        Return
    EndIf
    
    If GUICtrlRead($manual_time) = "" Or GUICtrlRead($manual_time) = 0 Then
        MsgBox(262144, "Add Task", "Please enter a time entry first.")
        Return
    EndIf
    
    If GUICtrlRead($manual_time) < 10 Then
        $m_time = 0 & GUICtrlRead($manual_time)
    Else
        $m_time = GUICtrlRead($manual_time)
    EndIf
    
    If GUICtrlRead($time_combo) = "mins" Then
        $mtime = "00:" & $m_time & ":00"
    Else
        $mtime = $m_time & ":00:00"
    EndIf
    
    $add_confirm = MsgBox(262180, "StopWatch", "Are you sure you want to add " & $mtime & " to " & GUICtrlRead($task_combo) & "?")

    If $add_confirm = 6 Then
        IniReadSection($tINI, @MON & "/" & @MDAY & "/" & @YEAR)
        If @error Then
            $sLongDayName = _DateDayOfWeek(@WDAY)
            $sLongMonthName = _DateToMonth(@MON)
            IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $sLongDayName & ", " & $sLongMonthName & " " & @MDAY & ", " & @YEAR, "-")
        EndIf
        
        $prev_time = IniRead($tINI, @MON & "/" & @MDAY & "/" & @YEAR, GUICtrlRead($task_combo), "00:00:00")
        
        $duration = AddTime($mtime, $prev_time)
        
        IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, GUICtrlRead($task_combo), $duration)
    EndIf
    
    GUICtrlSetData($manual_time, 0)
    
    GUICtrlSetData($task_combo, "")
    GUICtrlSetData($task_combo, "" & LoadCombo(), "Select Task Type...")
    
EndFunc   ;==>AddTask

Func Summary()
    
    Check_tINI()
    
    $aSectionNames = IniReadSectionNames($tINI)
    Dim $aSummary_Sections[1000][3]

    For $i = 1 To $aSectionNames[0]
        If $aSectionNames[$i] = "TASK_TYPES" Then ContinueLoop

        $aReadSection = IniReadSection($tINI, $aSectionNames[$i])
        If @error Then ContinueLoop

        For $j = 1 To $aReadSection[0][0]
            $aSummary_Sections[0][0] += 1

            $aSummary_Sections[$aSummary_Sections[0][0]][0] = $aReadSection[$j][0]
            $aSummary_Sections[$aSummary_Sections[0][0]][1] = IniRead($tINI, "TASK_TYPES", $aReadSection[$j][0], "")
            $aSummary_Sections[$aSummary_Sections[0][0]][2] = $aReadSection[$j][1]
        Next
    Next

    ReDim $aSummary_Sections[$aSummary_Sections[0][0] + 1][3]

    ;$Arr[0][0] is the elements count
    ;$Arr[N][0] is the Key Name
    ;$Arr[N][1] is the Key Value from "TASK_TYPES" section
    ;$Arr[N][2] is the Key Value from current section
    _ArrayDisplay($aSummary_Sections, "Summary")


EndFunc   ;==>Summary

Func OpenArchive()
    
    If Not FileExists($tINItmp) Then
        MsgBox(262144, "Time Tracker", "Data automatically starts to archive after 7 days of entry.")
    Else
        ShellExecute($tINItmp)
    EndIf
    
EndFunc   ;==>OpenArchive

Func Xbutton()
    Exit
EndFunc   ;==>Xbutton
Link to comment
Share on other sites

I am NOT going to try and study a long script right now. Here is a simple demo using the array to manipulate multiple windows:

#include <Array.au3>

Global $avStopWatches[1] = [0]

; Create 5 stop watches and add them to the array
For $n = 1 to 5
    _ArrayAdd($avStopWatches, StopWatch())
Next

; Move them all
For $n = 1 To 5
    WinMove($avStopWatches[$n], "", $n * 100, $n * 100, 200 + ($n * 50), 100 + ($n * 25), 10)
Next

; Delete them all
For $n = 1 To 5
    Sleep(1000)
    GUIDelete($avStopWatches[$n])
Next

Func StopWatch()
    $stopwatch_child = GUICreate("StopWatch", 150, 110)
    GUISetState()
   ; ...
    Return $stopwatch_child
EndFunc;==>StopWatch

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

im actually not trying to start x amount of stopwatches at a time.. i have a button where the user can spawn off however many they'd like...so i did this:

i still did a Global declaration of this:

$avStopWatches[1] = [0]oÝ÷ ÚËh§­r-YajËay«­¢+ØÀÌØíÍѽÁÝÑ¡}¡¥±ôU%
ÉÑ ÅÕ½ÐíMѽÁ]Ñ ÅÕ½Ðì°ÄÔÀ°ÄÄÀ°´Ä°´Ä°ÀÌØí]M}a}5%
!%1¤(¸¸¸)U%MÑMÑÑ ¤$)IÑÕɸÀÌØíÍѽÁÝÑ¡}¡¥±

the problem im facing now is with the stop button on each stopwatch child window - it always tries to stop the LAST spawned window (not sure how to cross reference the corresponding child window)

Link to comment
Share on other sites

heres the stop() function (sorry couldnt edit the last post to add this)

Func Stop_Time()
    
    If $flag = 0 Then
        GUIDelete($stopwatch_child)
        Return
    EndIf
    
    $count = $_time
    
    $task = StringSplit(WinGetText($stopwatch_child, $stopwatch_label), "START", 1)
    $task = StringTrimRight($task[1], 1)
    
    ;$add_confirm = MsgBox(262180, "StopWatch", "Are you sure you want to add " & $_time & " to " & GUICtrlRead($task_combo) & "?")
    $add_confirm = MsgBox(262180, "StopWatch", "Are you sure you want to add " & $_time & " to " & $task & "?")

    If $add_confirm = 6 Then
        IniReadSection($tINI, @MON & "/" & @MDAY & "/" & @YEAR)
        If @error Then
            $sLongDayName = _DateDayOfWeek(@WDAY)
            $sLongMonthName = _DateToMonth(@MON)
            IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $sLongDayName & ", " & $sLongMonthName & " " & @MDAY & ", " & @YEAR, "-")
        EndIf
        
        $prev_time = IniRead($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $task, "00:00:00")
        
        $duration = AddTime($count, $prev_time)
        
        IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $task, $duration)
    EndIf
    
    $flag = 0
    
    GUICtrlSetData($task_combo, "")
    GUICtrlSetData($task_combo, "" & LoadCombo(), "Select Task Type...")
    
    GUIDelete($stopwatch_child)
    
EndFunc   ;==>Stop_Time
Edited by gcue
Link to comment
Share on other sites

the problem im facing now is with the stop button on each stopwatch child window - it always tries to stop the LAST spawned window (not sure how to cross reference the corresponding child window)

You are using Event Mode, so in the function called by the button, use @GUI_WinHandle, @GUI_CtrlID, and @GUI_CtrlHandle to know where the event came from.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

interesting variables.. but how do you use these identifiers to make up conditions to later act on them?

if @gui_ctrlid = ?? then

but if these identifiers keep changing --- this is where i get confused..

thanks for your help =)

Link to comment
Share on other sites

interesting variables.. but how do you use these identifiers to make up conditions to later act on them?

if @gui_ctrlid = ?? then

but if these identifiers keep changing --- this is where i get confused..

thanks for your help =)

You would keep a dynamic list of the GUI and\or control identities as you created/deleted them. The macros would tell you which item in those lists was used.

For example, one array should track the window handles of all the windows. The @GUI_WinHandle macro will tell you which of those was acted on. If they all had OK buttons, then you might have an array of all the OK buttons' handles and look it up with @GUI_CtrlHandle. Or, you might just check the text of the button and see if it = "OK". The possibilities are endless.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

ok cool..

so the part i have a question on is how to act on a specific handle? using an if statement? if this is the case how do i know what its currently set to? sorry this aspect is pretty new to me..

thanks for all your help!

Link to comment
Share on other sites

Maybe like this

Func Stop_Time()
    
    If $flag = 0 Then
        GUIDelete(@GUI_WinHandle)
        Return
    EndIf
    
    $count = $_time
    
    $task = StringSplit(WinGetText(WInGetTitle(@GUI_WinHandle) , $stopwatch_label), "START", 1);<-------??????????don't know what you are trying to do here
    $task = StringTrimRight($task[1], 1);<----max of 9 tasks?
    
   ;$add_confirm = MsgBox(262180, "StopWatch", "Are you sure you want to add " & $_time & " to " & GUICtrlRead($task_combo) & "?");
    $add_confirm = MsgBox(262180, "StopWatch", "Are you sure you want to add " & $_time & " to " & $task & "?")

    If $add_confirm = 6 Then
        IniReadSection($tINI, @MON & "/" & @MDAY & "/" & @YEAR)
        If @error Then
            $sLongDayName = _DateDayOfWeek(@WDAY)
            $sLongMonthName = _DateToMonth(@MON)
            IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $sLongDayName & ", " & $sLongMonthName & " " & @MDAY & ", " & @YEAR, "-")
        EndIf
        
        $prev_time = IniRead($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $task, "00:00:00")
        
        $duration = AddTime($count, $prev_time)
        
        IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $task, $duration)
    EndIf
    
    $flag = 0
    
    GUICtrlSetData($task_combo, "")
    GUICtrlSetData($task_combo, "" & LoadCombo(), "Select Task Type...")
    
    GUIDelete(@GUI_WinHandle )
    
EndFunc  ;==>Stop_Time
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

ok im stuck.. ive built the arrays for the buttons (start/stop) and for the stopwatch_child gui also

not sure how to avoid the cross function mixups - help!

#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <file.au3>
#include <GuiComboBox.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <array.au3>
#include <GuiButton.au3>
#include <Timers.au3>
#include <Date.au3>

Opt("GUIOnEventMode", 1)

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent($exititem, "Xbutton")

TraySetState(1)

Global $tINI = (@ScriptDir & "\timetracker.ini"), $add_child, $OK_btn, $stopwatch_child, $time, $timer, $flag = 0
Global $tINItmp = (@ScriptDir & "\archive.txt"), $hour, $mins, $secs, $_time, $task_combo, $task_type, $PACS_ID
Global $manual_time, $time_combo, $avStopWatches[1] = [0], $start_btns[1] = [0], $stop_btns[1] = [0]

If Not FileExists($tINI) Then

    $text = '[TASK_TYPES]' & @CRLF
    $text &= 'Desktop Support=DSKSPT' & @CRLF
    $text &= 'General Admin=ADMIN-1' & @CRLF
    $text &= 'Mobile Support=MOBDEVSPT' & @CRLF
    $text &= 'PC Retire=KSSX' & @CRLF
    $text &= 'PC Setup=KSSX' & @CRLF
    $text &= 'Printer Support=PRNTSPT' & @CRLF
    $text &= 'Voice Support=VOICESPT' & @CRLF

    FileWrite($tINI, $text)

EndIf

GUICreate("Time Tracker", 415, 80); WS_EX_ACCEPTFILES

$filemenu = GUICtrlCreateMenu("&File")
$fileitem = GUICtrlCreateMenuItem("Open Archive", $filemenu)
GUICtrlSetOnEvent(-1, "OpenArchive")
$fileitem = GUICtrlCreateMenuItem("Exit", $filemenu)
GUICtrlSetOnEvent(-1, "Xbutton")


$task_combo = GUICtrlCreateCombo("Select Task Type...", 10, 5, 200, 20, $CBS_DROPDOWNLIST); create combobox and set first item
GUICtrlSetData(-1, LoadCombo(), "Select Task Type...")

$ADD_TYPE_btn = GUICtrlCreateButton("ADD", 10, 32, 20, 16, $BS_ICON)
GUICtrlSetImage($ADD_TYPE_btn, "dashboard.dll", 7)
GUICtrlSetOnEvent($ADD_TYPE_btn, "AddType_GUI")
GUICtrlSetTip($ADD_TYPE_btn, "Add Task Type")

$DEL_btn = GUICtrlCreateButton("DEL", 35, 32, 20, 16, $BS_ICON)
GUICtrlSetImage($DEL_btn, "dashboard.dll", 8)
GUICtrlSetOnEvent($DEL_btn, "DelType_GUI")
GUICtrlSetTip($DEL_btn, "Remove Task Type")

$manual_time = GUICtrlCreateInput(0, 220, 5, 40, 24)
GUICtrlSetTip($manual_time, "Enter Time Manually")

$p15_btn = GUICtrlCreateButton("", 265, 10, 14, 14, $BS_ICON)
GUICtrlSetImage($p15_btn, "dashboard.dll", 9)
GUICtrlSetOnEvent($p15_btn, "Plus15")
GUICtrlSetTip($p15_btn, "Add 15")

$m15_btn = GUICtrlCreateButton("", 285, 10, 14, 14, $BS_ICON)
GUICtrlSetImage($m15_btn, "dashboard.dll", 10)
GUICtrlSetOnEvent($m15_btn, "Minus15")
GUICtrlSetTip($m15_btn, "Minus 15")

$time_combo = GUICtrlCreateCombo("", 305, 5, 60, 20, $CBS_DROPDOWNLIST); create combobox and set first item
GUICtrlSetData(-1, "mins|hours", "mins") ; add other item snd set a new default

$ADD_TASK_btn = GUICtrlCreateButton("ADD", 375, 5, 24, 24, $BS_ICON)
GUICtrlSetImage($ADD_TASK_btn, "dashboard.dll", 7)
GUICtrlSetOnEvent($ADD_TASK_btn, "AddTask")
GUICtrlSetTip($ADD_TASK_btn, "Add Task")

$SW_btn = GUICtrlCreateButton("stopwatch", 270, 32, 65, 20)
GUICtrlSetOnEvent($SW_btn, "pStopWatch")
GUICtrlSetTip($SW_btn, "Time Me")

$SMRY_btn = GUICtrlCreateButton("summary", 340, 32, 60, 20)
GUICtrlSetOnEvent($SMRY_btn, "Summary")
GUICtrlSetTip($SMRY_btn, "View Summary")

GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState()

Check_tINI()

While 1
    Sleep(1)
WEnd

Func Check_tINI()
    
    $aSectionNames = IniReadSectionNames($tINI)
    Dim $aSummary_Sections[1000][2]

    If @error Then
        MsgBox(64, "Summary", "No time entries have been entered.")
        Return
    Else
        For $i = 1 To $aSectionNames[0]
            If $aSectionNames[$i] = "TASK_TYPES" Then ContinueLoop

            If $i > 8 Then
                $copy = IniReadSection($tINI, $aSectionNames[2])
                IniWriteSection($tINItmp, $aSectionNames[2], $copy)
                
                IniDelete($tINI, $aSectionNames[2])
            EndIf
            
        Next
    EndIf

EndFunc   ;==>Check_tINI

Func LoadCombo()

    Local $arr = IniReadSection($tINI, "TASK_TYPES"), $sAssets
    If Not @error Then
        For $i = 1 To $arr[0][0]
            $sAssets &= $arr[$i][0] & "|"
        Next
        Return StringTrimRight($sAssets, 1)
    EndIf

    Return "Nothing loaded"

EndFunc   ;==>LoadCombo

Func Plus15()
    
    $new_val = GUICtrlRead($manual_time) + 15
    GUICtrlSetData($manual_time, $new_val)
    
EndFunc   ;==>Plus15

Func Minus15()
    
    If GUICtrlRead($manual_time) <> 0 Then
        $new_val = GUICtrlRead($manual_time) - 15
        GUICtrlSetData($manual_time, $new_val)
    EndIf
    
EndFunc   ;==>Minus15

Func AddType_GUI()

    $add_child = GUICreate("Add Task Type", 470, 100, -1, -1, $WS_EX_MDICHILD)

    GUICtrlCreateLabel("Task Type:", 10, 10)
    $task_type = GUICtrlCreateInput("", 10, 35, 230, 20, $ES_UPPERCASE)
    
    GUICtrlCreateLabel("PACS ID:", 260, 10)
    $PACS_ID = GUICtrlCreateInput("", 260, 35, 90, 20, $ES_UPPERCASE)
    
    $OK_btn = GUICtrlCreateButton("OK", 365, 35, 30, 20)
    GUICtrlSetOnEvent($OK_btn, "AddType")
    
    $CANCEL_btn = GUICtrlCreateButton("CANCEL", 400, 35, 60, 20)
    GUICtrlSetOnEvent($CANCEL_btn, "DEL_add_child")

    GUISetState()

EndFunc   ;==>AddType_GUI

Func DEL_add_child()
    GUIDelete($add_child)
EndFunc   ;==>DEL_add_child

Func AddType()

    If GUICtrlRead($task_type) = "" Then
        MsgBox(262144, "Add Task Type", "Please enter a Task Type.")
        Return
    EndIf

    If GUICtrlRead($PACS_ID) = "" Then
        MsgBox(262144, "Add Task Type", "Please enter a PACS ID.")
        Return
    EndIf
    
    $search = IniRead($tINI, "TASK_TYPES", GUICtrlRead($task_type), "NOT_FOUND")
    If $search <> "NOT_FOUND" Then
        MsgBox(262144, "Add Task Type", "That Task Type already exists, please choose another.")
        GUISwitch($add_child)
        GUICtrlSetData($task_type, "")
        Return
    EndIf

    IniWrite($tINI, "TASK_TYPES", GUICtrlRead($task_type), GUICtrlRead($PACS_ID))
    
    $entries = ("TASK_TYPES")
    $entries_temp = ($entries & "_TEMP")

    $sort = IniReadSection($tINI, $entries)
    
    _ArraySort($sort, 0, 1)

    IniWriteSection($tINI, $entries_temp, $sort)
    IniDelete($tINI, $entries)
    IniRenameSection($tINI, $entries_temp, $entries)
    
    GUICtrlSetData($task_combo, "")
    GUICtrlSetData($task_combo, "" & LoadCombo(), GUICtrlRead($task_type))

    GUIDelete($add_child)

EndFunc   ;==>AddType

Func DelType_GUI()
    
    $current_selection = GUICtrlRead($task_combo)
    If $current_selection = "Select Task Type..." Then
        MsgBox(262144, "Remove Task Type", "Please select a Task Type first.")
        Return
    EndIf
    
    $del_confirm = MsgBox(262180, "Remove Task Type", "Are you sure you want to remove " & GUICtrlRead($task_combo) & "?")
    
    If $del_confirm = 6 Then
        IniDelete($tINI, "TASK_TYPES", GUICtrlRead($task_combo))
        
        $entries = ("TASK_TYPES")
        $entries_temp = ($entries & "_TEMP")

        $sort = IniReadSection($tINI, $entries)
        
        _ArraySort($sort, 0, 1)

        IniWriteSection($tINI, $entries_temp, $sort)
        IniDelete($tINI, $entries)
        IniRenameSection($tINI, $entries_temp, $entries)
        
        GUICtrlSetData($task_combo, "")
        GUICtrlSetData($task_combo, "" & LoadCombo(), "Select Task Type...")
    EndIf

    If $del_confirm = 7 Then
        Return
    EndIf
    
EndFunc   ;==>DelType_GUI

Func pStopWatch()
    _ArrayAdd($avStopWatches, StopWatch())
EndFunc   ;==>pStopWatch

Func StopWatch()
    
    $current_selection = GUICtrlRead($task_combo)
    If $current_selection = "Select Task Type..." Or $current_selection = "" Then
        MsgBox(262144, "StopWatch", "Please select a Task Type first.")
        Return
    EndIf
    
    If WinExists("StopWatch", GUICtrlRead($task_combo)) Then
        MsgBox(262144, "StopWarch", "There is already a StopWatch for " & GUICtrlRead($task_combo))
        Return
    EndIf
    
    $stopwatch_child = GUICreate("StopWatch", 150, 110, -1, -1, $WS_EX_MDICHILD)
    
    GUICtrlCreateLabel(GUICtrlRead($task_combo), 10, 5)

    $start_btn = GUICtrlCreateButton("START", 10, 30, 50, 20)
    GUICtrlSetOnEvent($start_btn, "pStart_Time")
    
    $stop_btn = GUICtrlCreateButton("STOP", 70, 30, 50, 20)
    GUICtrlSetOnEvent($stop_btn, "pStop_Time")

    GUISetState()
    
    Return $stopwatch_child
    Return $start_btn
    Return $stop_btn
    
EndFunc   ;==>StopWatch

Func pStart_Time()
    _ArrayAdd($start_btns, Start_Time())
EndFunc   ;==>pStart_Time

Func Start_Time()
    
    ;$flag = 1
    
    $timer = TimerInit()
    AdlibEnable("Update_Time", 50)
    
    ;GUISwitch(@GUI_WinHandle)
    $time = GUICtrlCreateLabel("00:00:00", 10, 58)
    
EndFunc   ;==>Start_Time

Func pStop_Time()
    _ArrayAdd($stop_btns, Stop_Time())
EndFunc   ;==>pStop_Time

Func Stop_Time()
    
    ;GUISwitch(@GUI_WinHandle)
    
    If $_time = "" Then
        GUIDelete($stopwatch_child)
        Return
    EndIf
    
    $count = $_time
    
    $add_confirm = MsgBox(262180, "StopWatch", "Are you sure you want to add " & $_time & " to " & GUICtrlRead($task_combo) & "?")

    If $add_confirm = 6 Then
        IniReadSection($tINI, @MON & "/" & @MDAY & "/" & @YEAR)
        If @error Then
            $sLongDayName = _DateDayOfWeek(@WDAY)
            $sLongMonthName = _DateToMonth(@MON)
            IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $sLongDayName & ", " & $sLongMonthName & " " & @MDAY & ", " & @YEAR, "-")
        EndIf
        
        $prev_time = IniRead($tINI, @MON & "/" & @MDAY & "/" & @YEAR, GUICtrlRead($task_combo), "00:00:00")
        
        $duration = AddTime($count, $prev_time)
        
        IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, GUICtrlRead($task_combo), $duration)
    EndIf
    
    $flag = 0
    
    GUICtrlSetData($task_combo, "")
    GUICtrlSetData($task_combo, "" & LoadCombo(), "Select Task Type...")
    
    GUIDelete(@GUI_WinHandle)
    
EndFunc   ;==>Stop_Time

Func AddTime($TIME1, $TIME2)
    
    Local $MIN_CARRY = 0, $HOUR_CARRY = 0
    $SPLIT1 = StringSplit($TIME1, ":")
    $SPLIT2 = StringSplit($TIME2, ":")
    $SEC = Number($SPLIT1[3]) + Number($SPLIT2[3])
    While $SEC >= 60
        $SEC -= 60
        $MIN_CARRY += 1
    WEnd
    $MIN = Number($SPLIT1[2]) + Number($SPLIT2[2])
    $MIN += $MIN_CARRY
    While $MIN >= 60
        $MIN -= 60
        $HOUR_CARRY += 1
    WEnd
    $hour = Number($SPLIT1[1]) + Number($SPLIT2[1])
    $hour += $HOUR_CARRY
    If $hour >= 24 Then
        Return "ERROR"
    Else
        $hour = String($hour)
        $MIN = String($MIN)
        $SEC = String($SEC)
        If StringLen($hour) < 2 Then $hour = "0" & $hour
        If StringLen($MIN) < 2 Then $MIN = "0" & $MIN
        If StringLen($SEC) < 2 Then $SEC = "0" & $SEC
        Return $hour & ":" & $MIN & ":" & $SEC
    EndIf
    
EndFunc   ;==>AddTime

Func Update_Time()
    
    _TicksToTime(Int(TimerDiff($timer)), $hour, $mins, $secs)
    Local $sTime = $_time ; save current time to be able to test and avoid flicker..
    $_time = StringFormat("%02i:%02i:%02i", $hour, $mins, $secs)
    If $sTime <> $_time Then ControlSetText(@GUI_WinHandle, "", $time, $_time)
    
EndFunc   ;==>Update_Time

Func AddTask()
    
    $current_selection = GUICtrlRead($task_combo)
    If $current_selection = "Select Task Type..." Or $current_selection = "" Then
        MsgBox(262144, "Add Task", "Please select a Task Type first.")
        Return
    EndIf
    
    If GUICtrlRead($manual_time) = "" Or GUICtrlRead($manual_time) = 0 Then
        MsgBox(262144, "Add Task", "Please enter a time entry first.")
        Return
    EndIf
    
    If GUICtrlRead($manual_time) < 10 Then
        $m_time = 0 & GUICtrlRead($manual_time)
    Else
        $m_time = GUICtrlRead($manual_time)
    EndIf
    
    If GUICtrlRead($time_combo) = "mins" Then
        $mtime = "00:" & $m_time & ":00"
    Else
        $mtime = $m_time & ":00:00"
    EndIf
    
    $add_confirm = MsgBox(262180, "StopWatch", "Are you sure you want to add " & $mtime & " to " & GUICtrlRead($task_combo) & "?")

    If $add_confirm = 6 Then
        IniReadSection($tINI, @MON & "/" & @MDAY & "/" & @YEAR)
        If @error Then
            $sLongDayName = _DateDayOfWeek(@WDAY)
            $sLongMonthName = _DateToMonth(@MON)
            IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, $sLongDayName & ", " & $sLongMonthName & " " & @MDAY & ", " & @YEAR, "-")
        EndIf
        
        $prev_time = IniRead($tINI, @MON & "/" & @MDAY & "/" & @YEAR, GUICtrlRead($task_combo), "00:00:00")
        
        $duration = AddTime($mtime, $prev_time)
        
        IniWrite($tINI, @MON & "/" & @MDAY & "/" & @YEAR, GUICtrlRead($task_combo), $duration)
    EndIf
    
    GUICtrlSetData($manual_time, 0)
    
    GUICtrlSetData($task_combo, "")
    GUICtrlSetData($task_combo, "" & LoadCombo(), "Select Task Type...")
    
EndFunc   ;==>AddTask

Func Summary()
    
    Check_tINI()
    
    $aSectionNames = IniReadSectionNames($tINI)
    Dim $aSummary_Sections[1000][3]

    For $i = 1 To $aSectionNames[0]
        If $aSectionNames[$i] = "TASK_TYPES" Then ContinueLoop

        $aReadSection = IniReadSection($tINI, $aSectionNames[$i])
        If @error Then ContinueLoop

        For $j = 1 To $aReadSection[0][0]
            $aSummary_Sections[0][0] += 1

            $aSummary_Sections[$aSummary_Sections[0][0]][0] = $aReadSection[$j][0]
            $aSummary_Sections[$aSummary_Sections[0][0]][1] = IniRead($tINI, "TASK_TYPES", $aReadSection[$j][0], "")
            $aSummary_Sections[$aSummary_Sections[0][0]][2] = $aReadSection[$j][1]
        Next
    Next

    ReDim $aSummary_Sections[$aSummary_Sections[0][0] + 1][3]

    ;$Arr[0][0] is the elements count
    ;$Arr[N][0] is the Key Name
    ;$Arr[N][1] is the Key Value from "TASK_TYPES" section
    ;$Arr[N][2] is the Key Value from current section
    
    ;_ArrayDisplay($aSummary_Sections, "Summary")
    _ArrayDisplay($aSummary_Sections, "Summary")


EndFunc   ;==>Summary

Func OpenArchive()
    
    If Not FileExists($tINItmp) Then
        MsgBox(262144, "Time Tracker", "Data automatically starts to archive after 7 days of entry.")
    Else
        ShellExecute($tINItmp)
    EndIf
    
EndFunc   ;==>OpenArchive

Func Xbutton()
    Exit
EndFunc   ;==>Xbutton
Link to comment
Share on other sites

ok im stuck.. ive built the arrays for the buttons (start/stop) and for the stopwatch_child gui also

not sure how to avoid the cross function mixups - help!

Func StopWatch()
    
    $current_selection = GUICtrlRead($task_combo)
    If $current_selection = "Select Task Type..." Or $current_selection = "" Then
        MsgBox(262144, "StopWatch", "Please select a Task Type first.")
        Return
    EndIf
    
    If WinExists("StopWatch", GUICtrlRead($task_combo)) Then
        MsgBox(262144, "StopWarch", "There is already a StopWatch for " & GUICtrlRead($task_combo))
        Return
    EndIf
    
    $stopwatch_child = GUICreate("StopWatch", 150, 110, -1, -1, $WS_EX_MDICHILD)
    
    GUICtrlCreateLabel(GUICtrlRead($task_combo), 10, 5)

    $start_btn = GUICtrlCreateButton("START", 10, 30, 50, 20)
    GUICtrlSetOnEvent($start_btn, "pStart_Time")
    
    $stop_btn = GUICtrlCreateButton("STOP", 70, 30, 50, 20)
    GUICtrlSetOnEvent($stop_btn, "pStop_Time")

    GUISetState()[
    
    Return $stopwatch_child
    Return $start_btn
    Return $stop_btn
    
EndFunc  ;==>StopWatch
The first 'Return' exits the function, so the next two are never executed. You can only return ONE value with 'Return' so the other two don't make it out of the function unless you use some Global variable (or array) first, or pass them into the function ByRef.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

hmm i did declare a global array for those variables..

Global $manual_time, $time_combo, $avStopWatches[1] = [0], $start_btns[1] = [0], $stop_btns[1] = [0]

what if i did Return $stopwatch, $start_btn, $stop_btn ? (prob wouldnt matter huh?)
Link to comment
Share on other sites

hmm i did declare a global array for those variables..

what if i did Return $stopwatch, $start_btn, $stop_btn ? (prob wouldnt matter huh?)

Well, yes you did declare the arrays. But how are the values from the function getting into the arrays? Why not just put them there in the function?
Func StopWatch()
    
    ; ...
        
    $stopwatch_child = GUICreate("StopWatch", 150, 110, -1, -1, $WS_EX_MDICHILD)
    GUICtrlCreateLabel(GUICtrlRead($task_combo), 10, 5)
    _ArrayAdd($avStopWatches, $stopwatch_child)
    
    $start_btn = GUICtrlCreateButton("START", 10, 30, 50, 20)
    GUICtrlSetOnEvent($start_btn, "pStart_Time")
    _ArrayAdd($start_btns, $start_btn)
    
    $stop_btn = GUICtrlCreateButton("STOP", 70, 30, 50, 20)
    GUICtrlSetOnEvent($stop_btn, "pStop_Time")
    _ArrayAdd($stop_btns, $stop_btn)
    
    GUISetState()
EndFunc ;==>StopWatch

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

good idea.

ok i still have the same problem:

i startup a stopwatch and the count starts as normal

but when i start up another stopwatch the count on the first stopwatch stops updating and the new stowatch count updates only on the new window

so i think the updatetime() function is only running on the previous stopwatch window..

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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