Sign in to follow this  
Followers 0
dragonlord

Clockticks - Adding

13 posts in this topic

Morning:

User comes online : Timervar=TimerInit()

User goes offline : TimerDiff(Timervar)

Print the time for which user was online

Noon:

User comes online : Timervar=TimerInit()

User goes offline : TimerDiff(Timervar)

Print the time for which user was online

Evening:

User comes online : Timervar=TimerInit()

User goes offline : TimerDiff(Timervar)

Print the time for which user was online

-I need to figure how much time a user was online during an entire day(total time).

Adding up all the above 3 TimerDiff variables and converting them using _TicksToTime seems to be giving gibberish.

Any thoughts please ? ....

Share this post


Link to post
Share on other sites



dragonlord,

I would expect this script to give an answer of about 3000:

$iBegin = TimerInit()
Sleep(1000)
$nInterval_1 = TimerDiff($iBegin)

$iBegin = TimerInit()
Sleep(1000)
$nInterval_2 = TimerDiff($iBegin)

$iBegin = TimerInit()
Sleep(1000)
$nInterval_3 = TimerDiff($iBegin)

$nTotal = $nInterval_1 + $nInterval_2 + $nInterval_3

ConsoleWrite($nTotal & @CRLF)

And that is what it does. :)

Perhaps if you posted your script we might be able to spot a problem. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

And if I take Melba23's code and plugin _TicksToTime I get 00:00:03

Global $iHour, $iMin, $iSec

$nTotal = $nInterval_1 + $nInterval_2 + $nInterval_3

_TicksToTime($nTotal, $iHour, $iMin, $iSec)

MsgBox(0, '', $nTotal & @CRLF & StringFormat('%02i:%02i:%02i', $iHour, $iMin, $iSec))

So yea, we'll need a bit more info.


[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks melba23, Prodigy for your suggestions.

Below's the code where i'm trying to do this.

Now i understand what youre trying to tell, but i'm getting lost in my own code, its a mess. Still trying to figure out what i'm doing wrong....

(Search for the line which says "resetting time to 0". the problem area is the few lines below that....)

#include <GUIConstants.au3>
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiComboBox.au3>
#include <GuiComboBoxEx.au3>
#include <Date.au3>
#include <String.au3>

Dim $UserArray[1][2]
Dim $TimeArray[1][2]
Dim $TotalTimeArray[1][2]
Dim $ItemsFromLV
Dim $begin,$CurrColor,$StartCtr,$col2,$col3, $iHours, $iMins, $iSecs,$iHours2, $iMins2, $iSecs2,$tHours, $tMins, $tSecs
Global $testCtr=0
$Green=0x98FB98
$Gray=0xEEDFCC
$Red=0xFF6A6A
$LVM_FIRST1 = 0x1000
$LVM_SCROLL1 = ($LVM_FIRST1 + 20)
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
$oCommunicator = ObjCreate("Communicator.UIAutomation")
If Not IsObj($oCommunicator ) Then
   MsgBox(48,"Error","l;llkklk")
EndIf
If @error then
   MsgBox(48,"Error","l;llkklk")
EndIf
#Region ### Start First Tab
$Form1_1 = GUICreate("Time Cop", 615, 550, -1, -1)
$Tab1 = GUICtrlCreateTab(8, 8, 601, 535)
$TabSheet1 = GUICtrlCreateTabItem("Monitor")
GUICtrlCreateLabel("user@domain.com : ", 32, 59, 101, 17)
$emailInp = GUICtrlCreateInput("gil.ipe@mycompany.com", 136, 56, 153, 21)
GUICtrlCreateLabel("Monitored Users: ", 380, 35, 101, 17)
$mylist = GUICtrlCreateList("", 380, 50, 220, 125, -1, 0)
$CurrentStatusLV = GUICtrlCreateListView("Time|User|Previous|Current", 16, 184, 586, 350, -1, Bitor($LVS_EX_GRIDLINES,$LVS_EX_HEADERDRAGDROP,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 120)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 100)
$Button1 = GUICtrlCreateButton("Monitor User", 136, 88, 155, 25)
$TabSheet2 = GUICtrlCreateTabItem("Extras")
$AlertMe_Chk=GUICtrlCreateCheckbox ( "Alert when someone is away for more than ", 32, 50 )
$AlertMe_Inp=GUICtrlCreateInput("30",250,50,40)
GUICtrlCreateUpdown($AlertMe_Inp);
GUICtrlCreateLabel(" minutes ", 290,54)
$AwayTimeLV = GUICtrlCreateListView("User|Current Away time|Total Away time Today", 16, 184, 586, 350, -1, Bitor($LVS_EX_GRIDLINES,$LVS_EX_HEADERDRAGDROP,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 220)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 200)
$Button3 = GUICtrlCreateButton("Export to Excel", 509, 92, 83, 25)
GUICtrlCreateTabItem("")
$Button4 = GUICtrlCreateButton("About", 533, 1, 75, 25)
LoadUsersFromFile()
GUISetState()
While 1
   sleep(10)
$nMsg = GUIGetMsg()
FOR $i=0 to UBound($UserArray,1)-1
$element=$UserArray[$i][0]
  if (StringLen($element) > 0) And ($element<> "user@mycompany.com") Then
   $PrevStatus=$UserArray[$i][1]
   $CurrStatus=_getContactStatus($element)
  
   If $CurrStatus <> $PrevStatus Then
    GuiCtrlCreateListViewItem(@MON &"/"& @MDAY &"/"& @YEAR & " " & @HOUR &":"& @MIN &":"& @SEC & "|" &_StringProper(StringReplace ( $element, "@mycompany.com", ""))&"|"&$PrevStatus&"|"&$CurrStatus,$CurrentStatusLV)
       If $CurrStatus="ONLINE" or $CurrStatus="BUSY" Then
       $CurrColor=$Green
       EndIf
       If $CurrStatus="OFFLINE" or $CurrStatus="APPEARING OFFLINE" Then
       $CurrColor=$Red
       EndIf
       If $CurrStatus="UNKNOWN" or $CurrStatus="INACTIVE" or $CurrStatus="AWAY" or $CurrStatus="BE RIGHT BACK" Then
       $CurrColor=$Gray
       EndIf
       GUICtrlSetBkColor(-1, $CurrColor)
       GUICtrlSendMsg($CurrentStatusLV, $LVM_SCROLL1, 0, 250)
    $UserArray[$i][1]=$CurrStatus
       If $CurrColor=$Green Then
       $foundAt=_ArraySearch($TimeArray, $element ,0 ,0 ,0,0,1, 0)
       If Not @error Then
        _TicksToTime(TimerDiff($TimeArray[$foundAt][1]),  $iHours, $iMins, $iSecs)
        ConsoleWrite("resetting time to 0 for "&$element&". Need to save previous ticks "&$TimeArray[$foundAt][1]&" which is "&$iHours&":"&$iMins&":"&$iSecs)
        $TotalTimeArray[$foundAt][1]=$TotalTimeArray[$foundAt][1]+$TimeArray[$foundAt][1]
       _TicksToTime(TimerDiff($TotalTimeArray[$foundAt][1]),  $iHours, $iMins, $iSecs)
        ConsoleWrite(", Cumulative value = "&$TimeArray[$foundAt][1]&" which is "&$iHours&":"&$iMins&":"&$iSecs&@CRLF)
       $TimeArray[$foundAt][1]=0
       EndIf
      
    Else
       $foundAt=_ArraySearch($TimeArray, $element ,0 ,0 ,0,0,1, 0)
       If Not @error Then
       $TimeArray[$foundAt][1]=TimerInit()
       EndIf
       EndIf
   EndIf
  EndIf
  NEXT
   FOR $i=0 to UBound($TimeArray,1)-2
   if $TimeArray[$i][1]=0 then
   $col2="Online"
   Else
   _TicksToTime(TimerDiff($TimeArray[$i][1]),  $iHours, $iMins, $iSecs)
   $col2=$iHours&":"&$iMins&":"&$iSecs
  
   If $TotalTimeArray[$i][1]<>0 Then
   _TicksToTime(TimerDiff($TotalTimeArray[$i][1]),  $iHours, $iMins, $iSecs)
   $col3=$iHours&":"&$iMins&":"&$iSecs
   Else
   $col3="00:00:00"
   EndIf
  
   EndIf
   $iI = _GUICtrlListView_FindText($AwayTimeLV,   StringUpper(StringReplace ( $TimeArray[$i][0], "@mycompany.com", "")))
  _GUICtrlListView_SetItemText($AwayTimeLV, $iI,$col2,1)
     _GUICtrlListView_SetItemText($AwayTimeLV, $iI,$col3,2)
   If GUICtrlRead($AlertMe_Chk)=1 Then
   If $iMins>= GUICtrlRead($AlertMe_Inp) Then
     ;TrayTip("Away Alert", $TimeArray[$i][0] &" is away for "&$iMins&" minutes", 1, 1)
   EndIf
   EndIf
   Next
   Select
   Case $nmsg = $GUI_EVENT_CLOSE
        ExitLoop
   Case $nmsg = $button1
   AddNewUser(GUICtrlRead($emailInp))
   Case $nmsg = $button3
  _GUICtrlListView_SaveCSV($CurrentStatusLV, @ScriptDir & "Export.csv")
   Case $nmsg = $Tab1
   Case $nmsg = $AlertMe_Chk
  If GUICtrlRead($AlertMe_Chk)=1 Then
     TrayTip("Away Alert", "Set to "&GUICtrlRead($AlertMe_Inp)&" minutes", 1, 1)
  Else
     TrayTip("Away Alert", "Disabled", 1, 1)
     EndIf
   EndSelect
WEnd
Func _getContactStatus($contactName)
$m = $oCommunicator.GetContact($contactName, $oCommunicator.MyServiceID)
if @error Then
  MsgBox(4096,"","Error resolving contact information !")
  EndIf
$statusName = _GetStatusName($m.Status())
return $statusName
EndFunc
func _GetStatusName($var)
;add code for In Meeting and Do not Disturb
Switch $var
   Case 0
    return "UNKNOWN"
   Case 1
    return "OFFLINE"
   Case 2
    return "ONLINE"
   Case 10
    return "BUSY"
   Case 18
    return "INACTIVE"
   Case 34
    return "AWAY"
   Case 14
    return "BE RIGHT BACK"
   Case 6
    return "APPEARING OFFLINE"

EndSwitch
EndFunc
Func _IsExistingUser($searchStr)
local $found =-1
FOR $x=0 to UBound($UserArray,1)-1
  FOR $y=0 to UBound($UserArray,2)-1
   if $searchStr = $UserArray[$x][$y] Then
    $found=1
   EndIf
  Next
Next
return $found
EndFunc
Func _GUICtrlListView_SaveCSV($hListView, $sFile, $sDelimiter = ",", $sQuote = '"')
Local $hFileOpen, $iError = 0, $sItem, $sString
Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView)
Local $iItemCount = _GUICtrlListView_GetItemCount($hListView)
For $A = 0 To $iItemCount - 1
  For $B = 0 To $iColumnCount - 1
   $sItem = _GUICtrlListView_GetItemText($hListView, $A, $B)
   $sString &= $sQuote & StringReplace($sItem, $sQuote, $sQuote & $sQuote, 0, 1) & $sQuote
   If $B < $iColumnCount - 1 Then
    $sString &= $sDelimiter
   EndIf
  Next
  $sString &= @CRLF
Next
$hFileOpen = FileOpen($sFile, 2)
FileWrite($hFileOpen, $sString)
FileClose($hFileOpen)
If @error Then
  $iError = 1
EndIf
Return SetError($iError, 0, $sFile)
EndFunc  
Func LoadUsersFromFile()
   Local $var = IniReadSection(@ScriptDir&"Timecop.ini", "UserList")
   If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
   
    For $i = 1 To $var[0][0]
     If $var[$i][0]="User" Then
     AddNewUser($var[$i][1])
   EndIf
    Next
EndIf
EndFunc
Func AddNewUser($userId)
   $CurrentUser=$userId
   If not StringInStr ($CurrentUser, "@mycompany.com") Then
    MsgBox(48,"Error","Invalid email")
   Else
      $search=_IsExistingUser($CurrentUser)
      if $search=-1 Then
       if _getContactStatus($CurrentUser)="UNKNOWN" Then
       MsgBox(16,"Error","Unable to get Communicator status. Please ensure " &$CurrentUser& " is valid !")
       Else
       $CurrStatus=_getContactStatus($CurrentUser)
        GUICtrlSetData($mylist,$CurrentUser&"|")
        $UserArray[UBound($UserArray,1)-1][0]=$CurrentUser
        $UserArray[UBound($UserArray,1)-1][1]=$CurrStatus
        ReDim $UserArray[UBound($UserArray,1)+1][2]
        GuiCtrlCreateListViewItem(@MON &"/"& @MDAY &"/"& @YEAR & " " & @HOUR &":"& @MIN &":"& @SEC & "|" &_StringProper(StringReplace($CurrentUser,"@mycompany.com", ""))&"| |"&$CurrStatus,$CurrentStatusLV)
       
      $TimeArray[UBound($TimeArray,1)-1][0]=$CurrentUser
      $TimeArray[UBound($TimeArray,1)-1][1]=0
     
      $TotalTimeArray[UBound($TotalTimeArray,1)-1][0]=$CurrentUser
      $TotalTimeArray[UBound($TotalTimeArray,1)-1][1]=0
     
     
       If $CurrStatus="ONLINE" or $CurrStatus="BUSY" Then $CurrColor=$Green
       If $CurrStatus="OFFLINE" or $CurrStatus="APPEARING OFFLINE" Then $CurrColor=$Red
       If $CurrStatus="UNKNOWN" or $CurrStatus="INACTIVE" or $CurrStatus="AWAY" or $CurrStatus="BE RIGHT BACK" Then $CurrColor=$Gray
     
      If $CurrColor<>$Green Then
      $TimeArray[UBound($TimeArray,1)-1][1]=TimerInit()
      ;$TotalTimeArray[UBound($TimeArray,1)-1][1]=TimerInit()
      EndIf
      If $CurrColor=$Green Then
      $TimeArray[UBound($TimeArray,1)-1][1]=0
      ;$TotalTimeArray[UBound($TimeArray,1)-1][1]=0
      EndIf
     
      ReDim $TimeArray[UBound($TimeArray,1)+1][2]
      ReDim $TotalTimeArray[UBound($TotalTimeArray,1)+1][2]
      
      GUICtrlSetBkColor(-1, $CurrColor)
      GUICtrlSendMsg($CurrentStatusLV, $LVM_SCROLL1, 0, 250)
     
      GuiCtrlCreateListViewItem(_StringProper(StringReplace ( $CurrentUser, "@mycompany.com", ""))&"|0",$AwayTimeLV)
       EndIf
      Else
      EndIf
   EndIf
EndFunc
  
Func _GUICtrlListView_CreateArray($hListView, $sDelimeter = '|')
    Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView), $iDim = 0, $iItemCount = _GUICtrlListView_GetItemCount($hListView)
    If $iColumnCount < 3 Then
        $iDim = 3 - $iColumnCount
    EndIf
    If $sDelimeter = Default Then
        $sDelimeter = '|'
    EndIf
    Local $aColumns = 0, $aReturn[$iItemCount + 1][$iColumnCount + $iDim] = [[$iItemCount, $iColumnCount, '']]
    For $i = 0 To $iColumnCount - 1
        $aColumns = _GUICtrlListView_GetColumn($hListView, $i)
        $aReturn[0][2] &= $aColumns[5] & $sDelimeter
    Next
    $aReturn[0][2] = StringTrimRight($aReturn[0][2], StringLen($sDelimeter))
    For $i = 0 To $iItemCount - 1
        For $j = 0 To $iColumnCount - 1
            $aReturn[$i + 1][$j] = _GUICtrlListView_GetItemText($hListView, $i, $j)
        Next
    Next
    Return SetError(Number($aReturn[0][0] = 0), 0, $aReturn)
EndFunc  

Func MyErrFunc()
   $HexNumber=hex($oMyError.number,8)
   if $HexNumber=80020009 Then
      Msgbox(48,"Time Cop","You are not signed in to Office Communicator !")
   Exit
   Else
   Msgbox(0,"","Intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription )
   EndIf
Endfunc
Edited by dragonlord

Share this post


Link to post
Share on other sites

dragonlord,

Although I cannot run your script, it looks to me as if the problem lies in this section:

If Not @error Then

    ; Here you work out the time the user was online using TimerDiff <<<<<<<<<<<<<<<<<<<<<<<<<<<<
    _TicksToTime(TimerDiff($TimeArray[$foundAt][1]), $iHours, $iMins, $iSecs)

    ConsoleWrite("resetting time to 0 for " & $element & ". Need to save previous ticks " & $TimeArray[$foundAt][1] & " which is " & $iHours & ":" & $iMins & ":" & $iSecs)

    ; And here you add that value to the total <<<<<<<<<<<<<<<<<<<<<<<<<<
    $TotalTimeArray[$foundAt][1] = $TotalTimeArray[$foundAt][1] + $TimeArray[$foundAt][1]

    ; But why are you again using TimerDiff here?  Surely you just need the _TicksToTime? <<<<<<<<<<<<<<<<<<<
    _TicksToTime(TimerDiff($TotalTimeArray[$foundAt][1]), $iHours, $iMins, $iSecs)

    ConsoleWrite(", Cumulative value = " & $TimeArray[$foundAt][1] & " which is " & $iHours & ":" & $iMins & ":" & $iSecs & @CRLF)
    $TimeArray[$foundAt][1] = 0
EndIf

Try that and see if it works. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

and this is what i get :(

resetting time to 0 for gil.ipe. Need to save previous ticks 1028567859857 which is 0:0:7, Cumulative value = 1028567859857 which is 285713:17:39
resetting time to 0 for gil.ipe. Need to save previous ticks 1028654428933 which is 0:0:11, Cumulative value = 1028654428933 which is 571450:38:8

The Cumulative value and its HH:MM::SS values are super weird

Edited by dragonlord

Share this post


Link to post
Share on other sites

dragonlord,

So where do you actually save the number of ticks that you have worked out? That value of 1028567859857 looks like the return from TimerInit and not the return from TimerDiff. :huh:

Perhaps you need to do something like this:

If Not @error Then

    ; How long was the user online? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $nLength = TimerDiff($TimeArray[$foundAt][1])
    ; And save it - you no longer need the initial timestamp <<<<<<<<<<<<<<<<<<<<<<<<
    $TimeArray[$foundAt][1]
    ; Convert it to HH:MM:SS for humans <<<<<<<<<<<<<<<<<<<<<<<<<<
    _TicksToTime($nLength, $iHours, $iMins, $iSecs)
    ConsoleWrite("resetting time to 0 for " & $element & ". Need to save previous ticks " & $TimeArray[$foundAt][1] & " which is " & $iHours & ":" & $iMins & ":" & $iSecs)

    ; Here you add that value to the total <<<<<<<<<<<<<<<<<<<<<<<<<<
    $TotalTimeArray[$foundAt][1] = $TotalTimeArray[$foundAt][1] + $TimeArray[$foundAt][1]
    ; And convert it <<<<<<<<<<<<<<<<<<<
    _TicksToTime($TotalTimeArray[$foundAt][1], $iHours, $iMins, $iSecs)

    ConsoleWrite(", Cumulative value = " & $TimeArray[$foundAt][1] & " which is " & $iHours & ":" & $iMins & ":" & $iSecs & @CRLF)

    ; And now reset ready for the next TimerInit <<<<<<<<<<<<<<<<<<<<<<<<
    $TimeArray[$foundAt][1] = 0
EndIf

Any better? Not being able to run the script is a real problem - but I am trying my best. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

I cant imagine how you'd be helping me out without beijng able to run it. (Needs MS Office communicator, which i'm sure you figured already :) ).

Code doesnt seem to make a difference.

Cumulative value still wrong.

Almost at the verge of giving up ....

resetting time to 0 for gil.ipe. Need to save previous ticks 1033644466944 which is 0:0:6, Cumulative value = 1033644466944 which is 287123:27:46
resetting time to 0 for gil.ipe. Need to save previous ticks 1033672880699 which is 0:0:10, Cumulative value = 1033672880699 which is 574254:49:7

Share this post


Link to post
Share on other sites

I cant imagine how you'd be helping me out without beijng able to run it. (Needs MS Office communicator, which i'm sure you figured already :) ).

Which is why you should post a reproducer, not your actual script. A short, working, example script that demonstrates your problem/question. First it narrows down the problem which helps you to find the resolution yourself, but if you can't solve it, it's easier for others to help you also.

Now it looks to me like you are adding to the return from TimerInit(), and that's just not going to work. The handle from TimerInit() is for TimerDiff() only.

$TotalTimeArray[$foundAt][1] = $TotalTimeArray[$foundAt][1] + $TimeArray[$foundAt][1]

$TimeArray is an array of TimerInit()'s, right? Big mess right there.

Don't give up. I'm sure you can figure it out ;)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

To further what Admiral was saying (and I'm going on memory) but I believe TimerInit uses some internal clock and does not start at 0.

What TimerDiff does is take the value of when TimerInit started and subtract from the current value of TimerInit to give you the milliseconds that have passed between the TimerInit values.

Example:

$time = TimerInit();<<The internal clock's START time

;do some stuff

$difference = TimerDiff($time);<<START time subtracted from Internal clock's CURRENT time

so the time between start and current would be held in $difference

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

And you might accumulate time and express it like this

local $st = timerinit()                     ; start first timed interval
sleep(6000)
local $intrvl1 = timerdiff($st)             ; # of milli secs for 1st interval
$st = timerinit()                           ; start second interval
sleep(3000)
local $intrvl2 = timerdiff($st)             ; # of milli secs for 2nd interval
local $duration = $intrvl1 + $intrvl2       ; accumulation of monitored time

consolewrite('! Duration = ' & stringformat( '%02i:%02i:%02i', _
                                                floor( ($duration/1000)/60^2), _
                                                mod(   ($duration/1000)/60,60 ), _
                                                mod(   ($duration/1000), 60 )) & @lf)

(* - some of the code happily plagarized from BrewmanNH)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

To further what Admiral was saying (and I'm going on memory) but I believe TimerInit uses some internal clock and does not start at 0.

What TimerDiff does is take the value of when TimerInit started and subtract from the current value of TimerInit to give you the milliseconds that have passed between the TimerInit values.

It's a little more involved than that. Look at the source for _Timer_Diff(), it's basically the same.

Posted from Nokia N900

Share this post


Link to post
Share on other sites

dragonlord,

I cant imagine how you'd be helping me out without beijng able to run it

With that attitude you can be sure you will not be getting any more sugestions from me. :bye:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • guinness
      By guinness
      This is for my C# fans out there who enjoy OOP. I have created a really rough draft (I mean it's super basic) of the Stopwatch Class in .NET, because I had the idea whilst travelling home and just thought it's neat to show a different paradigm to that of procedural programming.
       
      Enjoy.

      #include <WinAPISys.au3> Global Const $STOPWATCH_GUID = '804835D8-0DF4-11E4-A11F-29560707A45E', $STOPWATCH_TICKSPERMILLISECOND = 10000, $STOPWATCH_TICKSPERSECOND = $STOPWATCH_TICKSPERMILLISECOND * 1000 Global Enum $STOPWATCH_TIMER, $STOPWATCH_RUNNING, $STOPWATCH_ELAPSED, $STOPWATCH_ISHIGHRESOLUTION, $STOPWATCH_FREQUENCY, $STOPWATCH_TICKFREQUENCY, $STOPWATCH_ID, $STOPWATCH_MAX #Region Example Example() Func Example() Local $hStopWatch = Stopwatch() ConsoleWrite('IsRunning: ' & Stopwatch_IsRunning($hStopWatch) & @CRLF) ; Display running status. ConsoleWrite('Started' & @CRLF) Stopwatch_Start($hStopWatch) ; Start the stopwatch. ConsoleWrite('IsRunning: ' & Stopwatch_IsRunning($hStopWatch) & @CRLF) ; Display running status. Sleep(1000) ; Wait for 1 second. Stopwatch_Stop($hStopWatch) ; Stop the stopwatch. ConsoleWrite('Elapsed ms Time: ' & Stopwatch_ElapsedMilliseconds($hStopWatch) & @CRLF) ConsoleWrite('Stopped.' & @CRLF) ConsoleWrite('Waiting for 3 seconds whilst the stopwatch is stopped.' & @CRLF) Sleep(3000) ; Wait for 3 seconds. ConsoleWrite('Started' & @CRLF) Stopwatch_Start($hStopWatch) ; Start the stopwatch again. ConsoleWrite('Waiting for 2 seconds whilst the stopwatch is running' & @CRLF) Sleep(2000) ; Wait for 2 seconds. For $i = 1 To 10 ; The number of milliseconds is shown even when the stopwatch is running. ConsoleWrite('Elapsed ms Time: ' & Stopwatch_ElapsedMilliseconds($hStopWatch) & @CRLF) Sleep(250) Next Stopwatch_Stop($hStopWatch) ; Stop the stopwatch. ConsoleWrite('Elapsed ms Time: ' & Stopwatch_ElapsedMilliseconds($hStopWatch) & @CRLF) ; This should be about 5 seconds or so. ConsoleWrite('Stopped' & @CRLF) ConsoleWrite('IsRunning: ' & Stopwatch_IsRunning($hStopWatch) & @CRLF) ; Display running status. EndFunc ;==>Example #EndRegion Example ; Stopwatch Class: http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.110).aspx Func Stopwatch() Local $aStopwatch[$STOPWATCH_MAX] $aStopwatch[$STOPWATCH_ID] = $STOPWATCH_GUID Stopwatch_Reset($aStopwatch) $aStopwatch[$STOPWATCH_FREQUENCY] = _WinAPI_QueryPerformanceFrequency() If $aStopwatch[$STOPWATCH_FREQUENCY] > 0 Then $aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] = True $aStopwatch[$STOPWATCH_TICKFREQUENCY] = $STOPWATCH_TICKSPERSECOND $aStopwatch[$STOPWATCH_TICKFREQUENCY] /= $aStopwatch[$STOPWATCH_FREQUENCY] Else $aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] = False $aStopwatch[$STOPWATCH_FREQUENCY] = $STOPWATCH_TICKSPERSECOND $aStopwatch[$STOPWATCH_TICKFREQUENCY] = 1 EndIf Return $aStopwatch EndFunc ;==>Stopwatch Func Stopwatch_ElapsedMilliseconds(ByRef $aStopwatch) Return (__Stopwatch_IsStopwatch($aStopwatch) ? __Stopwatch_GetElapsedDateTimeTicks($aStopwatch) / $STOPWATCH_TICKSPERMILLISECOND : 0) EndFunc ;==>Stopwatch_ElapsedMilliseconds Func Stopwatch_ElapsedTicks(ByRef $aStopwatch) Return (__Stopwatch_IsStopwatch($aStopwatch) ? __Stopwatch_GetElapsedDateTimeTicks($aStopwatch) : 0) EndFunc ;==>Stopwatch_ElapsedTicks Func Stopwatch_IsRunning(ByRef $aStopwatch) Return (__Stopwatch_IsStopwatch($aStopwatch) ? $aStopwatch[$STOPWATCH_RUNNING] : Null) EndFunc ;==>Stopwatch_IsRunning Func Stopwatch_Reset(ByRef $aStopwatch) If __Stopwatch_IsStopwatch($aStopwatch) Then $aStopwatch[$STOPWATCH_ELAPSED] = 0 $aStopwatch[$STOPWATCH_RUNNING] = False $aStopwatch[$STOPWATCH_TIMER] = 0 EndIf Return True EndFunc ;==>Stopwatch_Reset Func Stopwatch_Restart(ByRef $aStopwatch) If __Stopwatch_IsStopwatch($aStopwatch) Then Stopwatch_Reset($aStopwatch) Stopwatch_Start($aStopwatch) EndIf Return True EndFunc ;==>Stopwatch_Restart Func Stopwatch_Start(ByRef $aStopwatch) If __Stopwatch_IsStopwatch($aStopwatch) And Not $aStopwatch[$STOPWATCH_RUNNING] Then $aStopwatch[$STOPWATCH_RUNNING] = True $aStopwatch[$STOPWATCH_TIMER] = __Stopwatch_GetTimestamp($aStopwatch) EndIf Return True EndFunc ;==>Stopwatch_Start Func Stopwatch_StartNew() Local $aStopwatch = Stopwatch() Stopwatch_Start($aStopwatch) Return $aStopwatch EndFunc ;==>Stopwatch_StartNew Func Stopwatch_Stop(ByRef $aStopwatch) If __Stopwatch_IsStopwatch($aStopwatch) And $aStopwatch[$STOPWATCH_RUNNING] Then $aStopwatch[$STOPWATCH_ELAPSED] = __Stopwatch_GetRawElapsedTicks($aStopwatch) $aStopwatch[$STOPWATCH_RUNNING] = False EndIf Return True EndFunc ;==>Stopwatch_Stop Func __Stopwatch_GetElapsedDateTimeTicks(ByRef $aStopwatch) Return (__Stopwatch_GetRawElapsedTicks($aStopwatch) * ($aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] ? $aStopwatch[$STOPWATCH_TICKFREQUENCY] : $STOPWATCH_TICKSPERMILLISECOND)) EndFunc ;==>__Stopwatch_GetElapsedDateTimeTicks Func __Stopwatch_GetRawElapsedTicks(ByRef $aStopwatch) Local $iElapsedTime = $aStopwatch[$STOPWATCH_ELAPSED] If $aStopwatch[$STOPWATCH_RUNNING] Then If $aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] Then Local $iTimeStamp = __Stopwatch_GetTimestamp($aStopwatch) $iTimeStamp = $iTimeStamp - $aStopwatch[$STOPWATCH_TIMER] $iElapsedTime += $iTimeStamp Else $iElapsedTime += TimerDiff($aStopwatch[$STOPWATCH_TIMER]) EndIf EndIf Return $iElapsedTime EndFunc ;==>__Stopwatch_GetRawElapsedTicks Func __Stopwatch_GetTimestamp(ByRef $aStopwatch) Return ($aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] ? _WinAPI_QueryPerformanceCounter() : TimerInit()) EndFunc ;==>__Stopwatch_GetTimestamp Func __Stopwatch_IsStopwatch(ByRef $aStopwatch) ; Internal function only. Return (UBound($aStopwatch) = $STOPWATCH_MAX And $aStopwatch[$STOPWATCH_ID] = $STOPWATCH_GUID) EndFunc ;==>__Stopwatch_IsStopwatch
    • Anne
      By Anne
      Hi everyone.
      I have a question and wasn't able to find any answer for this.
      What is the maximum value/limit for TimerInit & TimerDiff.
      I mean, If I use TimerInit() in my script, how long can it 'last'? How long will I be able to read it with TimerDiff()?
      I realize that the result of TimerDiff isn't an Integer. It's a floating number and I am not sure what the maximum value is.
      I would like my program to use $Time = TimerInit() today, and then I'll be able to use TimerDiff($Time) tomorrow or even the day after. Is this possible? and what happens if TimerDiff exceeds the maximum value (if there is any)?
    • n0pr0bl3m
      By n0pr0bl3m
      So I have some timers which I reset periodically, but my problem is that they don't wait for the functions before them to finish and in a strange way reset beforehand.

      -snip-

      timerinit doesnt wait the mouseclick and sleep functions to finish