Stopwatch with Lap feature

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Jun 23, 2013 1:30 pm

The stopwatch will now work in standard and military time. You can't switch between times while the stopwatch is running, or you will get a vbscript error. If you have to switch times, stop the stopwatch, exit it, change the time and start the stopwatch.

Code: Select all

//<--Start > Set Directory to save settings ini file to
Let>IniDir=C:\Program Files\Rains Stopwatch
IfDirExists>%IniDir%
  IfFileExists>%IniDir%\Stopwatch.ini
  ELSE
    WriteLn>%IniDir%\Stopwatch.ini,r,
  ENDIF
ELSE
  CreateDir>%IniDir%
  WriteLn>%IniDir%\Stopwatch.ini,r,
ENdif
//<--End > Set Directory to save settings ini file to

Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize]
  Caption = 'Stopwatch'
  ClientHeight = 368
  ClientWidth = 446
  Color = clBlack
  Ctl3D = False
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object Panel2: TPanel
    Left = 0
    Top = 0
    Width = 446
    Height = 368
    Align = alClient
    BevelOuter = bvNone
    Color = clBlack
    ParentBackground = False
    TabOrder = 0
    ExplicitWidth = 513
    ExplicitHeight = 449
    object Panel4: TPanel
      Left = 0
      Top = 341
      Width = 446
      Height = 27
      Align = alBottom
      BevelInner = bvLowered
      BevelKind = bkSoft
      BevelOuter = bvLowered
      Color = clWhite
      ParentBackground = False
      TabOrder = 0
      object Panel5: TPanel
        Left = 2
        Top = 2
        Width = 140
        Height = 19
        Align = alLeft
        ParentBackground = False
        TabOrder = 0
        object StatusBar1: TStatusBar
          Left = 1
          Top = -1
          Width = 138
          Height = 19
          Panels = <>
          SimplePanel = True
          SimpleText = '00:00:00:00.00'
        end
      end
      object Panel6: TPanel
        Left = 142
        Top = 2
        Width = 76
        Height = 19
        Align = alLeft
        ParentBackground = False
        TabOrder = 2
        object StatusBar2: TStatusBar
          Left = 1
          Top = -1
          Width = 74
          Height = 19
          Panels = <>
          SimplePanel = True
          SimpleText = '12:16 AM'
        end
      end
      object Panel8: TPanel
        Left = 218
        Top = 2
        Width = 222
        Height = 19
        Align = alClient
        ParentBackground = False
        TabOrder = 1
        object StatusBar3: TStatusBar
          Left = 1
          Top = -1
          Width = 220
          Height = 19
          Panels = <>
          SimplePanel = True
        end
      end
    end
    object Panel1: TPanel
      Left = 0
      Top = 0
      Width = 446
      Height = 60
      Align = alTop
      BevelInner = bvRaised
      BevelKind = bkTile
      BorderStyle = bsSizeable
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -24
      Font.Name = 'MS Sans Serif'
      Font.Style = [fsBold]
      ParentFont = False
      TabOrder = 1
      object Edit1: TEdit
        Left = 2
        Top = 2
        Width = 438
        Height = 52
        Cursor = crArrow
        Align = alClient
        Alignment = taCenter
        BevelInner = bvNone
        BevelOuter = bvNone
        BorderStyle = bsNone
        Color = clBlack
        Font.Charset = ANSI_CHARSET
        Font.Color = clWhite
        Font.Height = -35
        Font.Name = 'Arial Black'
        Font.Style = [fsBold]
        ParentFont = False
        ReadOnly = True
        TabOrder = 1
        Text = '00:00:00:00.00'
      end
      object MSButton1: tMSButton
        Left = 0
        Top = 0
        Width = 1
        Height = 1
        Caption = '&browse'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = []
        ParentFont = False
        TabOrder = 0
        DoBrowse = False
        Filename = 'Lap Times.txt'
        Filter = 'Text Document (*.txt)|*.txt|'
        BrowseStyle = fbOpen
      end
    end
    object Panel3: TPanel
      Left = 0
      Top = 60
      Width = 446
      Height = 281
      Align = alClient
      BevelInner = bvRaised
      BevelKind = bkTile
      TabOrder = 2
      ExplicitLeft = 56
      ExplicitTop = 56
      ExplicitWidth = 481
      object MSListBox1: tMSListBox
        Left = 2
        Top = 2
        Width = 438
        Height = 273
        Style = lbOwnerDrawFixed
        Align = alClient
        Color = -1
        ExtendedSelect = False
        Font.Charset = ANSI_CHARSET
        Font.Color = clWhite
        Font.Height = -16
        Font.Name = 'Arial Black'
        Font.Style = [fsBold]
        ItemHeight = 18
        ParentFont = False
        TabOrder = 0
        SelectedIndex = -1
        ExplicitLeft = 122
        ExplicitWidth = 413
      end
    end
  end
  object MainMenu: tMSMainMenu
    object MenuItem1: tMSMenuItem
      Caption = '&Options'
      object MenuItem42: tMSMenuItem
        Caption = 'S&tart (Ctrl+Alt+S)'
      end
      object MenuItem43: tMSMenuItem
        Caption = '&Lap (Ctrl+Alt+L)'
      end
      object MenuItem44: tMSMenuItem
        Caption = '&Reset (Ctrl+Alt+R)'
      end
      object MenuItem46: tMSMenuItem
        Caption = 'Clear Laps (Ctrl+Alt+C)'
      end
      object MenuItem45: tMSMenuItem
        Caption = '-'
      end
      object MenuItem2: tMSMenuItem
        AutoCheck = True
        Caption = '&Display in Title'
      end
      object MenuItem3: tMSMenuItem
        Caption = '-'
      end
      object MenuItem4: tMSMenuItem
        Caption = '&Open'
      end
      object MenuItem5: tMSMenuItem
        Caption = '&Save'
      end
      object MenuItem6: tMSMenuItem
        Caption = '-'
      end
      object MenuItem7: tMSMenuItem
        Caption = 'S&hrink Window'
      end
      object MenuItem8: tMSMenuItem
        Caption = '-'
      end
      object MenuItem9: tMSMenuItem
        AutoCheck = True
        Caption = '&Always on top'
      end
      object MenuItem10: tMSMenuItem
        Caption = '&Minimize to tray'
      end
      object MenuItem11: tMSMenuItem
        Caption = 'O&pacity'
        object MenuItem12: tMSMenuItem
          AutoCheck = True
          Caption = '&10%'
          RadioItem = True
        end
        object MenuItem13: tMSMenuItem
          AutoCheck = True
          Caption = '&20%'
          RadioItem = True
        end
        object MenuItem14: tMSMenuItem
          AutoCheck = True
          Caption = '&30%'
          RadioItem = True
        end
        object MenuItem15: tMSMenuItem
          AutoCheck = True
          Caption = '&40%'
          RadioItem = True
        end
        object MenuItem16: tMSMenuItem
          AutoCheck = True
          Caption = '&50%'
          RadioItem = True
        end
        object MenuItem17: tMSMenuItem
          AutoCheck = True
          Caption = '&60%'
          RadioItem = True
        end
        object MenuItem18: tMSMenuItem
          AutoCheck = True
          Caption = '&70%'
          RadioItem = True
        end
        object MenuItem19: tMSMenuItem
          AutoCheck = True
          Caption = '&80%'
          RadioItem = True
        end
        object MenuItem20: tMSMenuItem
          AutoCheck = True
          Caption = '&90%'
          RadioItem = True
        end
        object MenuItem21: tMSMenuItem
          Caption = '-'
        end
        object MenuItem22: tMSMenuItem
          AutoCheck = True
          Caption = '&Disabled'
          Checked = True
          RadioItem = True
        end
      end
      object MenuItem26: tMSMenuItem
        Caption = '&Font Color'
        object MenuItem27: tMSMenuItem
          Caption = 'Maroon'
        end
        object MenuItem28: tMSMenuItem
          Caption = 'Green'
        end
        object MenuItem29: tMSMenuItem
          Caption = 'Olive'
        end
        object MenuItem30: tMSMenuItem
          Caption = 'Navy'
        end
        object MenuItem31: tMSMenuItem
          Caption = 'Purple'
        end
        object MenuItem32: tMSMenuItem
          Caption = 'Teal'
        end
        object MenuItem33: tMSMenuItem
          Caption = 'Gray'
        end
        object MenuItem34: tMSMenuItem
          Caption = 'Silver'
        end
        object MenuItem35: tMSMenuItem
          Caption = 'Red'
        end
        object MenuItem36: tMSMenuItem
          Caption = 'Lime'
        end
        object MenuItem37: tMSMenuItem
          Caption = 'Yellow'
        end
        object MenuItem38: tMSMenuItem
          Caption = 'Blue'
        end
        object MenuItem39: tMSMenuItem
          Caption = 'Fuchsia'
        end
        object MenuItem40: tMSMenuItem
          Caption = 'Aqua'
        end
        object MenuItem41: tMSMenuItem
          Caption = 'White'
        end
      end
    end
    object MenuItem23: tMSMenuItem
      Caption = '&Start'
      Hint = 'Ctrl+Alt+S'
    end
    object MenuItem24: tMSMenuItem
      Caption = '&Lap'
      Hint = 'Ctrl+Alt+L'
    end
    object MenuItem25: tMSMenuItem
      Caption = '&Reset'
    end
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,ExitScript
AddDialogHandler>Dialog1,MenuItem4,OnClick,OpenFile
AddDialogHandler>Dialog1,MenuItem5,OnClick,SaveLapTimes
AddDialogHandler>Dialog1,MenuItem7,OnClick,ShrinkWindow
AddDialogHandler>Dialog1,MenuItem9,OnClick,SetOnTop
AddDialogHandler>Dialog1,MenuItem10,OnClick,MinimizeToTray
AddDialogHandler>Dialog1,MenuItem12,OnClick,SetOpacity(26)
AddDialogHandler>Dialog1,MenuItem13,OnClick,SetOpacity(51)
AddDialogHandler>Dialog1,MenuItem14,OnClick,SetOpacity(77)
AddDialogHandler>Dialog1,MenuItem15,OnClick,SetOpacity(102)
AddDialogHandler>Dialog1,MenuItem16,OnClick,SetOpacity(128)
AddDialogHandler>Dialog1,MenuItem17,OnClick,SetOpacity(153)
AddDialogHandler>Dialog1,MenuItem18,OnClick,SetOpacity(179)
AddDialogHandler>Dialog1,MenuItem19,OnClick,SetOpacity(204)
AddDialogHandler>Dialog1,MenuItem20,OnClick,SetOpacity(230)
AddDialogHandler>Dialog1,MenuItem22,OnClick,SetOpacity(False)
AddDialogHandler>Dialog1,MenuItem27,OnClick,SetFontColor(128)
AddDialogHandler>Dialog1,MenuItem28,OnClick,SetFontColor(32768)
AddDialogHandler>Dialog1,MenuItem29,OnClick,SetFontColor(32896)
AddDialogHandler>Dialog1,MenuItem30,OnClick,SetFontColor(8388608)
AddDialogHandler>Dialog1,MenuItem31,OnClick,SetFontColor(8388736)
AddDialogHandler>Dialog1,MenuItem32,OnClick,SetFontColor(8421376)
AddDialogHandler>Dialog1,MenuItem33,OnClick,SetFontColor(8421504)
AddDialogHandler>Dialog1,MenuItem34,OnClick,SetFontColor(12632256)
AddDialogHandler>Dialog1,MenuItem35,OnClick,SetFontColor(255)
AddDialogHandler>Dialog1,MenuItem36,OnClick,SetFontColor(65280)
AddDialogHandler>Dialog1,MenuItem37,OnClick,SetFontColor(65535)
AddDialogHandler>Dialog1,MenuItem38,OnClick,SetFontColor(16711680)
AddDialogHandler>Dialog1,MenuItem39,OnClick,SetFontColor(16711935)
AddDialogHandler>Dialog1,MenuItem40,OnClick,SetFontColor(16776960)
AddDialogHandler>Dialog1,MenuItem41,OnClick,SetFontColor(16777215)
AddDialogHandler>Dialog1,MenuItem23,OnClick,SetPauseState
AddDialogHandler>Dialog1,MenuItem24,OnClick,SetLapTime
AddDialogHandler>Dialog1,MenuItem25,OnClick,ResetTimer
AddDialogHandler>Dialog1,MenuItem42,OnClick,SetPauseState
AddDialogHandler>Dialog1,MenuItem43,OnClick,SetLapTime
AddDialogHandler>Dialog1,MenuItem44,OnClick,ResetTimer
AddDialogHandler>Dialog1,MenuItem46,OnClick,ClearLapList
AddDialogHandler>Dialog1,Panel2,OnResize,Resize

SetDialogProperty>Dialog1,Edit1,Text,00:00:00:00.00
SetDialogProperty>Dialog1,StatusBar1,SimpleText,00:00:00:00.00
SetDialogProperty>Dialog1,MSListBox1,Text,
SetDialogProperty>Dialog1,,BorderIcons,[biMaximize, biMinimize, biSystemMenu]
SetDialogProperty>Dialog1,Panel1,Visible,True
SetDialogProperty>Dialog1,Panel2,Visible,True
SetDialogProperty>Dialog1,Panel3,Visible,True
SetDialogProperty>Dialog1,MenuItem24,Visible,False
SetDialogProperty>Dialog1,MenuItem25,Visible,True
SetDialogProperty>Dialog1,MenuItem43,Enabled,False
SetDialogProperty>Dialog1,MenuItem44,Enabled,True
GetTime>TheTime
SetDialogProperty>Dialog1,StatusBar2,SimpleText,%TheTime%

//<--Start > Tray icon
IfFileExists>%TEMP_DIR%-cp-stop-watch-icon.ico
  del>%TEMP_DIR%-cp-stop-watch-icon.ico
ENDIF
ExportData>STOPWATCH16X16.ICO_DATA,%TEMP_DIR%-cp-stop-watch-icon.ico
AddTrayIcon>%TEMP_DIR%-cp-stop-watch-icon.ico,MyTrayIcon,Click to Show Stopwatch
AddTrayHandler>MyTrayIcon,OnMouseDown,ShowStopwatch
ModTrayIcon>MyTrayIcon,Click to Show Stopwatch,,False
//<--End > Tray icon

//<--Start > Set saved Opacity
ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Opacity,Opacity_Var
IF>Opacity_Var=
ELSE
  IF>%Opacity_Var%<>False
    SetDialogProperty>Dialog1,,AlphaBlend,True
    SetDialogProperty>Dialog1,,AlphaBlendValue,%Opacity_Var%
    SetDialogProperty>Dialog1,MenuItem22,Checked,False
    IF>Opacity_Var=26
      SetDialogProperty>Dialog1,MenuItem12,Checked,True
    ENDIF
    IF>Opacity_Var=51
      SetDialogProperty>Dialog1,MenuItem13,Checked,True
    ENDIF
    IF>Opacity_Var=77
      SetDialogProperty>Dialog1,MenuItem14,Checked,True
    ENDIF
    IF>Opacity_Var=102
      SetDialogProperty>Dialog1,MenuItem15,Checked,True
    ENDIF
    IF>Opacity_Var=128
      SetDialogProperty>Dialog1,MenuItem16,Checked,True
    ENDIF
    IF>Opacity_Var=153
      SetDialogProperty>Dialog1,MenuItem17,Checked,True
    ENDIF
    IF>Opacity_Var=179
      SetDialogProperty>Dialog1,MenuItem18,Checked,True
    ENDIF
    IF>Opacity_Var=204
      SetDialogProperty>Dialog1,MenuItem19,Checked,True
    ENDIF
    IF>Opacity_Var=230
      SetDialogProperty>Dialog1,MenuItem20,Checked,True
    ENDIF
  Endif
ENDIF
//<--End > Set saved Opacity

//<--Start > Set saved font color
ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Font Color,Font_Color
IF>Font_Color=
  Let>Font_Color=16777215
ENDIF
Let>Font_Name=Arial Black
Let>Font_Size=26
Let>Font_Style=1
SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
SetDialogObjectFont>Dialog1,MSListBox1,Arial Black,12,1,Font_Color
//<--End > Set saved font color

//<--Start > Saved Time Function
ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,SavedTimeRes
IF>SavedTimeRes=
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,0
ENDIF
ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,SavedTimeRes
IF>SavedTimeRes<>0
  Year>YY
  Month>MM
  Day>DD
  Hour>HH
  Min>NN
  Sec>SS
  Let>toDate=%YY%/%MM%/%DD% %HH%:%NN%:%SS%
  VBEval>Abs(DateDiff("s","%SavedTimeRes%","%toDate%")),DiffRes
  Let>SavedMilliseconds=%DiffRes%*1000
  Let>ContinueFromSavedTime=True
  ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Times,LapTimesRes
  Separate>%LapTimesRes%,;,Lap_List
  IF>Lap_List_Count>0
    SetDialogProperty>Dialog1,StatusBar3,SimpleText,%Lap_List_1%
  ENDIF
  
  StringReplace>%LapTimesRes%,;,%CRLF%,LapTimesRes
  SetDialogProperty>Dialog1,MSListBox1,Text,LapTimesRes
  ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Count,LapCounter
  ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Time,LapTickCount
  IF>LapTickCount=
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Time,0
    Let>LapTickCount=0
  ENDIF
  IF>LapCounter=
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Count,0
    Let>LapCounter=0
  ENDIF

ELSE
  Let>LapCounter=0
  Let>LapTickCount=0
  Let>HasBeenReset=True
ENDIF
//<--End > Saved Time Function

Show>Dialog1

OnEvent>KEY_DOWN,c,5,ClearLapList
OnEvent>KEY_DOWN,s,5,SetOneEventPauseState
GetDialogProperty>Dialog1,,Height,DialogHeight
GetDialogProperty>Dialog1,Panel1,Height,Panel1Height
GetDialogProperty>Dialog1,Panel3,Height,Panel3Height
GetDialogProperty>Dialog1,Panel4,Height,Panel4Height
Sub>DialogHeight,Panel1Height
Sub>DialogHeight,Panel3Height

Let>SavedLaps=
Let>TimerPaused=True
Let>SavedTickCount=0
Let>SecondsTickCount=0
Let>DaysElapsed=00
Let>HoursElapsed=00
Let>MinutesElapsed=00
Let>SecondsElapsed=00
Let>MilSecDisplay=.00
Let>EndTimer=0
Let>StartTimer=0

Let>NumOfSecPaused=0
Let>NumOfSavedSecPaused=0

Label>lblPause
  OnEvent>KEY_DOWN,l,5,
  SetDialogProperty>Dialog1,MenuItem24,Visible,False
  SetDialogProperty>Dialog1,MenuItem25,Visible,True
  SetDialogProperty>Dialog1,MenuItem43,Enabled,False
  SetDialogProperty>Dialog1,MenuItem44,Enabled,True
  Let>SavedTickCount=%EndTimer%-%StartTimer%
  //<--Start > Saved Time Function
  IF>SavedTimeRes<>0
    IF>SavedTimeAdded<>True
      Let>SavedTimeAdded=True
      Add>SavedTickCount,%SavedMilliseconds%
    ENDIF
    Timer>StartPauseTimer
  ENDIF
  //<--End > Saved Time Function
  
Label>lblPauseLoop
  //<--Start > Saved Time Function
  IF>SavedTimeRes<>0
   Timer>EndPauseTimer
   Let>NumOfSavedSecPaused={(%EndPauseTimer%-%StartPauseTimer%)/1000}
  ENDIF
  IF>ContinueFromSavedTime=True
    Let>ContinueFromSavedTime=False
    Let>ResetSavedTime=False
    Gosub>SetPauseState
  ENDIF
  //<--End > Saved Time Function

  //<--Start > Start timer when Start is clicked
  IF>TimerPaused=False
    Goto>lblStart
  ENDIF
  //<--End > Start timer when Start is clicked

  //<--Start > Display timer in dialog title when selected
  GetDialogProperty>Dialog1,MenuItem2,Checked,res
  If>res=True
  SetDialogProperty>Dialog1,,Caption,%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%%MilSecDisplay%
  Else
  SetDialogProperty>Dialog1,,Caption,Stopwatch
  ENDIF
  //<--END > Display timer in dialog title when selected
  

  //<--Start > Enable option to save laps or disable when there are none
  GetDialogProperty>Dialog1,MSListBox1,Text,SavedLaps
  IF>SavedLaps=
    SetDialogProperty>Dialog1,MenuItem5,Enabled,False
  ELSE
    SetDialogProperty>Dialog1,MenuItem5,Enabled,True
  Endif
  //<--Start > Enable option to save laps or disable when there are none
  
  //<--Start > Display time in status bar
  GetTime>TheTime
  SetDialogProperty>Dialog1,StatusBar2,SimpleText,%TheTime%
  //<--End > Display time in status bar

  //<--Start > update tray icon when dialog is minimized to tray
  GetDialogProperty>Dialog1,,Visible,dResult
  If>dResult=False
    Wait>.5
    GetDialogProperty>Dialog1,,Visible,dResult
    If>dResult=False
      ModTrayIcon>MyTrayIcon,%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%%MilSecDisplay% (Click to show),,True
    Endif
  Endif
  //<--End > update tray icon when dialog is minimized to tray

  Wait>.1
Goto>lblPauseLoop






Label>lblStart
  //<--Start > Saved Time Function
  Add>NumOfSecPaused,%NumOfSavedSecPaused%
  //<--End > Saved Time Function

  OnEvent>KEY_DOWN,l,5,SetOneEventLapTime
  SetDialogProperty>Dialog1,MenuItem25,Visible,False
  SetDialogProperty>Dialog1,MenuItem24,Visible,True
  SetDialogProperty>Dialog1,MenuItem43,Enabled,True
  SetDialogProperty>Dialog1,MenuItem44,Enabled,False
  Timer>StartTimer
Label>lblTimerLoop
  IF>TimerPaused=True
    Goto>lblPause
  ENDIF

  Timer>EndTimer
  
  Add>EndTimer,SavedTickCount


  Let>MillisecondsTickCount={(%EndTimer%-%StartTimer%)/1000}
  Position>%COMMA%,%MillisecondsTickCount%,1,DEC_SEPARATOR
  IF>DEC_SEPARATOR>0
    StringReplace>%MillisecondsTickCount%,%COMMA%,.,MillisecondsTickCount
  endif
  VBEval>FormatNumber(%MillisecondsTickCount%,2,-2,-2,0),ElapsedMilliseconds
  Position>%COMMA%,%ElapsedMilliseconds%,1,DEC_SEPARATOR
  IF>DEC_SEPARATOR>0
    StringReplace>%ElapsedMilliseconds%,%COMMA%,.,ElapsedMilliseconds
  ENDIF
  Position>.,%ElapsedMilliseconds%,1,DecPosition
  IF>DecPosition>0
    MidStr>%ElapsedMilliseconds%,%DecPosition%,10,MilSecDisplay
  ELSE
    Let>MilSecDisplay=00
  ENDIF
  
  Let>MainTickCount=%EndTimer%-%StartTimer%
  Let>SecondsTickCount={(%EndTimer%-%StartTimer%)/1000}
  Position>%COMMA%,%SecondsTickCount%,1,DEC_SEPARATOR
  IF>DEC_SEPARATOR>0
    StringReplace>%SecondsTickCount%,%COMMA%,.,SecondsTickCount
  ENDIF
  Let>ElapsedSeconds={Round(%SecondsTickCount%)}
  Let>DaysElapsed={%ElapsedSeconds% DIV 86400}
  Let>ElapsedSeconds={%ElapsedSeconds% MOD 86400}
  Let>HoursElapsed={%ElapsedSeconds% DIV 3600}
  Let>ElapsedSeconds={%ElapsedSeconds% MOD 3600}
  Let>MinutesElapsed={%ElapsedSeconds% DIV 60}
  Let>SecondsElapsed={%ElapsedSeconds% MOD 60}

  Len>%DaysElapsed%,ddLen
  Len>%HoursElapsed%,hhLen
  Len>%MinutesElapsed%,mmLen
  Len>%SecondsElapsed%,ssLen
  IF>ddLen=1
    Let>DaysElapsed=0%DaysElapsed%
  ENDIF
  IF>hhLen=1
    Let>HoursElapsed=0%HoursElapsed%
  ENDIF
  IF>mmLen=1
    Let>MinutesElapsed=0%MinutesElapsed%
  ENDIF
  IF>ssLen=1
    Let>SecondsElapsed=0%SecondsElapsed%
  ENDIF

  SetDialogProperty>Dialog1,StatusBar1,SimpleText,%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%%MilSecDisplay%
  SetDialogProperty>Dialog1,Edit1,Text,%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%%MilSecDisplay%
  SetDialogProperty>Dialog3,Edit1,Text,%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%%MilSecDisplay%
  GetDialogProperty>Dialog1,MenuItem2,Checked,res
  If>res=True
    SetDialogProperty>Dialog1,MenuItem2,BitmapData,DisplayTimerOff
    SetDialogProperty>Dialog1,,Caption,%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%%MilSecDisplay%
  Else
    SetDialogProperty>Dialog1,MenuItem2,BitmapData,DisplayTimerOn
    SetDialogProperty>Dialog1,,Caption,Stopwatch
  ENDIF

  GetTime>TheTime
  SetDialogProperty>Dialog1,StatusBar2,SimpleText,%TheTime%
  Wait>0.005
  

  
  GetDialogProperty>Dialog1,MSListBox1,Text,SavedLaps
  IF>SavedLaps=
    SetDialogProperty>Dialog1,MenuItem5,Enabled,False
  ELSE
    SetDialogProperty>Dialog1,MenuItem5,Enabled,True
  Endif
  
  GetDialogProperty>Dialog1,,Visible,dResult
  If>dResult=False
    Wait>.005
    GetDialogProperty>Dialog1,,Visible,dResult
    If>dResult=False
      ModTrayIcon>MyTrayIcon,%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%%MilSecDisplay% (Click to show),,True
    Endif
  Endif

Goto>lblTimerLoop








SRT>SetLapTime
  Len>%DaysElapsed%,ddLen
  Len>%HoursElapsed%,hhLen
  Len>%MinutesElapsed%,mmLen
  Len>%SecondsElapsed%,ssLen
  IF>ddLen=1
    Let>DaysElapsed=0%DaysElapsed%
  ENDIF
  IF>hhLen=1
    Let>HoursElapsed=0%HoursElapsed%
  ENDIF
  IF>mmLen=1
    Let>MinutesElapsed=0%MinutesElapsed%
  ENDIF
  IF>ssLen=1
    Let>SecondsElapsed=0%SecondsElapsed%
  ENDIF
  Let>DisplayCounter=%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%

  IF>LapCounter>0
    Let>TimeDiff={(%MainTickCount%-%LapTickCount%)/1000}
    Position>%COMMA%,%TimeDiff%,1,DEC_SEPARATOR
    IF>DEC_SEPARATOR>0
      StringReplace>%TimeDiff%,%COMMA%,.,TimeDiff
    ENDIF
    Let>LapMillisecondsTickCount={(%MainTickCount%-%LapTickCount%)/1000}
    Position>%COMMA%,%LapMillisecondsTickCount%,1,DEC_SEPARATOR
    IF>DEC_SEPARATOR>0
      StringReplace>%LapMillisecondsTickCount%,%COMMA%,.,LapMillisecondsTickCount
    ENDIF
    VBEval>FormatNumber(%LapMillisecondsTickCount%,2,-2,-2,0),ElapsedLapMilliseconds
    Position>%COMMA%,%ElapsedLapMilliseconds%,1,DEC_SEPARATOR
    IF>DEC_SEPARATOR>0
      StringReplace>%ElapsedLapMilliseconds%,%COMMA%,.,ElapsedLapMilliseconds
    ENDIF
    Position>.,%ElapsedLapMilliseconds%,1,DecPosition
    IF>DecPosition>0
      MidStr>%ElapsedLapMilliseconds%,%DecPosition%,10,MilLapSecDisplay
    ELSE
      Let>MilLapSecDisplay=00
    ENDIF
    Let>ElapsedSeconds={Round(%TimeDiff%)}
    Let>DaysElapsed={%ElapsedSeconds% DIV 86400}
    Let>ElapsedSeconds={%ElapsedSeconds% MOD 86400}
    Let>HoursElapsed={%ElapsedSeconds% DIV 3600}
    Let>ElapsedSeconds={%ElapsedSeconds% MOD 3600}
    Let>MinutesElapsed={%ElapsedSeconds% DIV 60}
    Let>SecondsElapsed={%ElapsedSeconds% MOD 60}
    
    Len>%DaysElapsed%,ddLen
    Len>%HoursElapsed%,hhLen
    Len>%MinutesElapsed%,mmLen
    Len>%SecondsElapsed%,ssLen
    IF>ddLen=1
      Let>DaysElapsed=0%DaysElapsed%
    ENDIF
    IF>hhLen=1
      Let>HoursElapsed=0%HoursElapsed%
    ENDIF
    IF>mmLen=1
      Let>MinutesElapsed=0%MinutesElapsed%
    ENDIF
    IF>ssLen=1
      Let>SecondsElapsed=0%SecondsElapsed%
    ENDIF

    Let>DisplayDiff=(%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%%MilLapSecDisplay%)
  ENDIF

  IF>LapCounter=0
    Let>TimeDiff=0
    Let>DisplayDiff=
  ENDIF

  Add>LapCounter,1
  Let>LapTickCount=%EndTimer%-%StartTimer%
  //<--Start > Saved Time Function
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Count,%LapCounter%
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Time,%LapTickCount%
  Let>LapTimesRes=Lap %LapCounter%: %DisplayCounter%%MilSecDisplay% %DisplayDiff%%CRLF%%SavedLaps%
  StringReplace>%LapTimesRes%,%CRLF%,;,LapTimesRes
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Times,%LapTimesRes%
  //<--End > Saved Time Function
  IF>LapCounter=1
    SetDialogProperty>Dialog1,MSListBox1,Text,Lap %LapCounter%: %DisplayCounter%%MilSecDisplay%%CRLF%%SavedLaps%
  ELSE
    SetDialogProperty>Dialog1,MSListBox1,Text,Lap %LapCounter%: %DisplayCounter%%MilSecDisplay% %DisplayDiff%%CRLF%%SavedLaps%
  ENDIF
  GetDialogProperty>Dialog1,MSListBox1,Text,SavedLaps
  SetDialogProperty>Dialog1,StatusBar3,SimpleText,Lap %LapCounter%: %DisplayCounter%%MilSecDisplay% %DisplayDiff%

  //<--Start > Saved Time Function
  IF>TimerPaused=False
    IF>HasBeenReset=True
      Year>YY
      Month>MM
      Day>DD
      Hour>HH
      Min>NN
      Sec>SS
      GetTime>TheTime
      EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,%YY%/%MM%/%DD% %TheTime%
    ELSE
      Let>NumOfSecToAdd={Round(%NumOfSecPaused%)}
      ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,SavedTimeRes
      VBEval>dateadd("s", "%NumOfSecPaused%", "%SavedTimeRes%"),NewTimeRes
      EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,%NewTimeRes%
    ENDIF

  ELSE
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Count,0
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Time,0
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,0
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Times,
  ENDIF
  //<--End > Saved Time Function

END>SetLapTime


SRT>SetOneEventLapTime
  Len>%DaysElapsed%,ddLen
  Len>%HoursElapsed%,hhLen
  Len>%MinutesElapsed%,mmLen
  Len>%SecondsElapsed%,ssLen
  IF>ddLen=1
    Let>DaysElapsed=0%DaysElapsed%
  ENDIF
  IF>hhLen=1
    Let>HoursElapsed=0%HoursElapsed%
  ENDIF
  IF>mmLen=1
    Let>MinutesElapsed=0%MinutesElapsed%
  ENDIF
  IF>ssLen=1
    Let>SecondsElapsed=0%SecondsElapsed%
  ENDIF
  Let>DisplayCounter=%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%

  IF>LapCounter>0
    Let>TimeDiff={(%MainTickCount%-%LapTickCount%)/1000}
    Position>%COMMA%,%TimeDiff%,1,DEC_SEPARATOR
    IF>DEC_SEPARATOR>0
      StringReplace>%TimeDiff%,%COMMA%,.,TimeDiff
    ENDIF
    Let>LapMillisecondsTickCount={(%MainTickCount%-%LapTickCount%)/1000}
    Position>%COMMA%,%LapMillisecondsTickCount%,1,DEC_SEPARATOR
    IF>DEC_SEPARATOR>0
      StringReplace>%LapMillisecondsTickCount%,%COMMA%,.,LapMillisecondsTickCount
    ENDIF
    VBEval>FormatNumber(%LapMillisecondsTickCount%,2,-2,-2,0),ElapsedLapMilliseconds
    Position>%COMMA%,%ElapsedLapMilliseconds%,1,DEC_SEPARATOR
    IF>DEC_SEPARATOR>0
      StringReplace>%ElapsedLapMilliseconds%,%COMMA%,.,ElapsedLapMilliseconds
    ENDIF
    Position>.,%ElapsedLapMilliseconds%,1,DecPosition
    IF>DecPosition>0
      MidStr>%ElapsedLapMilliseconds%,%DecPosition%,10,MilLapSecDisplay
    ELSE
      Let>MilLapSecDisplay=00
    ENDIF

    Let>ElapsedSeconds={Round(%TimeDiff%)}
    Let>DaysElapsed={%ElapsedSeconds% DIV 86400}
    Let>ElapsedSeconds={%ElapsedSeconds% MOD 86400}
    Let>HoursElapsed={%ElapsedSeconds% DIV 3600}
    Let>ElapsedSeconds={%ElapsedSeconds% MOD 3600}
    Let>MinutesElapsed={%ElapsedSeconds% DIV 60}
    Let>SecondsElapsed={%ElapsedSeconds% MOD 60}
    
    Len>%DaysElapsed%,ddLen
    Len>%HoursElapsed%,hhLen
    Len>%MinutesElapsed%,mmLen
    Len>%SecondsElapsed%,ssLen
    IF>ddLen=1
      Let>DaysElapsed=0%DaysElapsed%
    ENDIF
    IF>hhLen=1
      Let>HoursElapsed=0%HoursElapsed%
    ENDIF
    IF>mmLen=1
      Let>MinutesElapsed=0%MinutesElapsed%
    ENDIF
    IF>ssLen=1
      Let>SecondsElapsed=0%SecondsElapsed%
    ENDIF

    Let>DisplayDiff=(%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%%MilLapSecDisplay%)
  ENDIF

  IF>LapCounter=0
    Let>TimeDiff=0
    Let>DisplayDiff=
  ENDIF

  Add>LapCounter,1
  Let>LapTickCount=%EndTimer%-%StartTimer%
  //<--Start > Saved Time Function
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Count,%LapCounter%
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Time,%LapTickCount%
  Let>LapTimesRes=Lap %LapCounter%: %DisplayCounter%%MilSecDisplay% %DisplayDiff%%CRLF%%SavedLaps%
  StringReplace>%LapTimesRes%,%CRLF%,;,LapTimesRes
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Times,%LapTimesRes%
  //<--End > Saved Time Function
  IF>LapCounter=1
    SetDialogProperty>Dialog1,MSListBox1,Text,Lap %LapCounter%: %DisplayCounter%%MilSecDisplay%%CRLF%%SavedLaps%
  ELSE
    SetDialogProperty>Dialog1,MSListBox1,Text,Lap %LapCounter%: %DisplayCounter%%MilSecDisplay% %DisplayDiff%%CRLF%%SavedLaps%
  ENDIF
  GetDialogProperty>Dialog1,MSListBox1,Text,SavedLaps
  SetDialogProperty>Dialog1,StatusBar3,SimpleText,Lap %LapCounter%: %DisplayCounter%%MilSecDisplay% %DisplayDiff%

  //<--Start > Saved Time Function
  IF>TimerPaused=False
    IF>HasBeenReset=True
      Year>YY
      Month>MM
      Day>DD
      Hour>HH
      Min>NN
      Sec>SS
      GetTime>TheTime
      EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,%YY%/%MM%/%DD% %TheTime%
    ELSE
      Let>NumOfSecToAdd={Round(%NumOfSecPaused%)}
      ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,SavedTimeRes
      VBEval>dateadd("s", "%NumOfSecPaused%", "%SavedTimeRes%"),NewTimeRes
      EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,%NewTimeRes%
    ENDIF

  ELSE
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Count,0
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Time,0
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,0
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Times,
  ENDIF
  //<--End > Saved Time Function

  Wait>.2
END>SetOneEventLapTime








SRT>SetPauseState
  IF>TimerPaused=True
    Let>TimerPaused=False
    SetDialogProperty>Dialog1,MenuItem23,Caption,Stop
    SetDialogProperty>Dialog1,MenuItem42,Caption,Stop (Ctrl+Alt+S)
  ELSE
    SetDialogProperty>Dialog1,MenuItem23,Caption,Start
    SetDialogProperty>Dialog1,MenuItem42,Caption,Start (Ctrl+Alt+S)
    Let>TimerPaused=True
  ENDIF
END>SetPauseState


SRT>SetOneEventPauseState
  IF>TimerPaused=True
    Let>TimerPaused=False
    SetDialogProperty>Dialog1,MenuItem23,Caption,Stop
    SetDialogProperty>Dialog1,MenuItem42,Caption,Stop (Ctrl+Alt+S)
  ELSE
    SetDialogProperty>Dialog1,MenuItem23,Caption,Start
    SetDialogProperty>Dialog1,MenuItem42,Caption,Start (Ctrl+Alt+S)
    Let>TimerPaused=True
  ENDIF
  Wait>.1
END>SetOneEventPauseState


SRT>ResetTimer
  SetDialogProperty>Dialog1,Edit1,Text,00:00:00:00.00
  SetDialogProperty>Dialog1,StatusBar1,SimpleText,00:00:00:00.00
  Let>HasBeenReset=True
  Let>SavedTickCount=0
  Let>SavedLaps=
  Timer>StartTimer
  Let>LapCounter=0
  SetDialogProperty>Dialog1,MSListBox1,Text,
  SetDialogProperty>Dialog1,StatusBar3,SimpleText,
  Let>DaysElapsed=00
  Let>HoursElapsed=00
  Let>MinutesElapsed=00
  Let>SecondsElapsed=00
  Let>MilSecDisplay=.00
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Count,0
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Time,0
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,0
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Times,
END>ResetTimer


SRT>ClearLapList
  Let>LapCounter=0
  Let>LapTickCount=0
  Let>SavedLaps=
  SetDialogProperty>Dialog1,MSListBox1,Text,
  SetDialogProperty>Dialog1,StatusBar3,SimpleText,
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Count,0
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Time,0
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Times,
END>ClearLapList


SRT>OpenFile
  SetDialogProperty>Dialog1,,Visible,False
  SetDialogProperty>Dialog1,MSButton1,Filename,
  SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbOpen
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  ExtractFileName>%strFileName%,FileNameRes
  IF>FileNameRes<>
    ExecuteFile>strFileName
  ENDIF
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,False
  SetDialogProperty>Dialog1,MSButton1,Filename,Lap Times.txt
  SetDialogProperty>Dialog1,,Visible,True
END>OpenFile


SRT>SaveLapTimes
  SetDialogProperty>Dialog1,,Visible,False
  GetDialogProperty>Dialog1,MSListBox1,Text,SavedLaps
  IF>SavedLaps=
    LibFunc>user32,MessageBoxA,r,0,No laps to save,Stopwatch,270400
  ELSE
    SetDialogProperty>Dialog1,MSButton1,Filename,
    SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbSave
    SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
    GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
    ExtractFileName>%strFileName%,FileNameRes
    IF>FileNameRes<>
      GetDialogProperty>Dialog1,MSListBox1,Text,SavedLaps
      Del>%strFileName%
      ExtractFileExt>%strFileName%,ExtRes
      IF>ExtRes=.txt
        WriteLn>%strFileName%,res,%SavedLaps%
      ELSE
        WriteLn>%strFileName%.txt,res,%SavedLaps%
      ENDIF
    ENDIF
  ENDIF
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,False
  SetDialogProperty>Dialog1,,Visible,True
END>SaveLapTimes


SRT>SetOnTop
  GetDialogProperty>Dialog1,MenuItem9,Checked,res
  IF>res=True
    SetDialogProperty>Dialog1,,FormStyle,fsStayOnTop
  ELSE
    SetDialogProperty>Dialog1,,FormStyle,fsNormal
  ENDIF
END>SetOnTop


SRT>ShrinkWindow
  GetDialogProperty>Dialog1,MenuItem7,Caption,CaptionRes
  IF>CaptionRes=S&hrink Window
    SetDialogProperty>Dialog1,,BorderIcons,[biMinimize, biSystemMenu]
    SetDialogProperty>Dialog1,,BorderStyle,bsSingle
    
    SetDialogProperty>Dialog1,Panel1,BevelInner,bvNone
    SetDialogProperty>Dialog1,Panel1,BevelKind,bvNone
    SetDialogProperty>Dialog1,Panel1,BevelOuter,bvNone

    SetDialogProperty>Dialog1,Panel2,AutoSize,True
    SetDialogProperty>Dialog1,Panel3,Visible,False
    SetDialogProperty>Dialog1,Panel4,Visible,False
    SetDialogProperty>Dialog1,MenuItem7,Caption,Restore Window
    GetDialogProperty>Dialog1,,Height,TheHeight
    GetDialogProperty>Dialog1,,Width,TheWidth
    GetDialogProperty>Dialog1,Panel5,Width,Panel5TheWidth
    Add>Panel5TheWidth,50
    SetDialogProperty>Dialog1,,Width,%Panel5TheWidth%
    SetDialogProperty>Dialog1,,Height,%DialogHeight%
    SetDialogProperty>Dialog1,,AutoSize,True
    SetDialogProperty>Dialog1,,AutoSize,False
    
  ELSE
    SetDialogProperty>Dialog1,,BorderIcons,[biMaximize, biMinimize, biSystemMenu]
    SetDialogProperty>Dialog1,,BorderStyle,bsSizeable
    
    SetDialogProperty>Dialog1,Panel1,BevelInner,bvRaised
    SetDialogProperty>Dialog1,Panel1,BevelKind,bkTile
    SetDialogProperty>Dialog1,Panel1,BevelOuter,bvRaised
    
    SetDialogProperty>Dialog1,Panel2,AutoSize,False
    SetDialogProperty>Dialog1,Panel3,Visible,True
    SetDialogProperty>Dialog1,Panel4,Visible,True
    SetDialogProperty>Dialog1,MenuItem7,Caption,S&hrink Window
    SetDialogProperty>Dialog1,,Height,TheHeight
    SetDialogProperty>Dialog1,,Width,TheWidth
  ENDIF
END>ShrinkWindow


SRT>Resize
  GetDialogProperty>Dialog1,,Width,TheDialogWidth
  GetDialogProperty>Dialog1,MSListBox1,Text,SavedLaps
  IF>SavedLaps=
    SetDialogProperty>Dialog1,MSListBox1,ScrollWidth,0
  ELSE
   IF>{(%TheDialogWidth%<400)}
     SetDialogProperty>Dialog1,MSListBox1,ScrollWidth,370
   ELSE
     SetDialogProperty>Dialog1,MSListBox1,ScrollWidth,0
   ENDIF
  ENDIF
  
  IF>{(%TheDialogWidth%>301)}
    Let>Font_Name=Arial Black
    Let>Font_Size=26
    Let>Font_Style=1
    SetDialogProperty>Dialog1,Panel1,Height,60
    SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  ENDIF
  IF>{(%TheDialogWidth%<301)AND(%TheDialogWidth%>280)}
    Let>Font_Name=Arial Black
    Let>Font_Size=24
    Let>Font_Style=1
    SetDialogProperty>Dialog1,Panel1,Height,55
    SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  ENDIF
  IF>{(%TheDialogWidth%<280)AND(%TheDialogWidth%>260)}
    Let>Font_Name=Arial Black
    Let>Font_Size=22
    Let>Font_Style=1
    SetDialogProperty>Dialog1,Panel1,Height,50
    SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  ENDIF
  IF>{(%TheDialogWidth%<260)AND(%TheDialogWidth%>245)}
    Let>Font_Name=Arial Black
    Let>Font_Size=20
    Let>Font_Style=1
    SetDialogProperty>Dialog1,Panel1,Height,45
    SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  ENDIF
  IF>{(%TheDialogWidth%<245)AND(%TheDialogWidth%>220)}
    Let>Font_Name=Arial Black
    Let>Font_Size=18
    Let>Font_Style=1
    SetDialogProperty>Dialog1,Panel1,Height,40
    SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  ENDIF
  IF>{(%TheDialogWidth%<220)AND(%TheDialogWidth%>195)}
    Let>Font_Name=Arial Black
    Let>Font_Size=16
    Let>Font_Style=1
    SetDialogProperty>Dialog1,Panel1,Height,35
    SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  ENDIF
  IF>{(%TheDialogWidth%<195)AND(%TheDialogWidth%>180)}
    Let>Font_Name=Arial Black
    Let>Font_Size=14
    Let>Font_Style=1
    SetDialogProperty>Dialog1,Panel1,Height,32
    SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  ENDIF
  IF>{(%TheDialogWidth%<180)AND(%TheDialogWidth%>160)}
    Let>Font_Name=Arial Black
    Let>Font_Size=12
    Let>Font_Style=1
    SetDialogProperty>Dialog1,Panel1,Height,29
    SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  ENDIF
  IF>{(%TheDialogWidth%<160)AND(%TheDialogWidth%>0)}
    Let>Font_Name=Arial
    Let>Font_Size=10
    Let>Font_Style=1
    SetDialogProperty>Dialog1,Panel1,Height,25
    SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  ENDIF
END>Resize


SRT>MinimizeToTray
  IfFileExists>%TEMP_DIR%-cp-stop-watch-icon.ico
  ELSE
    ExportData>STOPWATCH16X16.ICO_DATA,%TEMP_DIR%-cp-stop-watch-icon.ico
  ENDIF

  GetDialogProperty>Dialog1,,Visible,dResult
  If>dResult=False
    SetDialogProperty>Dialog1,,Visible,True
  Endif
  ModTrayIcon>MyTrayIcon,Click to Show Stopwatch,,True
  SetDialogProperty>Dialog1,,Visible,False
  Wait>.2
END>MinimizeToTray


SRT>ShowStopwatch
  SetDialogProperty>Dialog1,,Visible,True
  ModTrayIcon>MyTrayIcon,Click to Show Stopwatch,,False
  Wait>.2
END>ShowStopwatch


SRT>SetOpacity
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Opacity,%SetOpacity_Var_1%
  IF>%SetOpacity_Var_1%=False
    SetDialogProperty>Dialog1,,AlphaBlend,False
    SetDialogProperty>Dialog1,,AlphaBlendValue,255
    SetDialogProperty>Dialog1,MenuItem22,Checked,True
  Else
    Let>OpacityValue=%SetOpacity_Var_1%
    SetDialogProperty>Dialog1,,AlphaBlend,True
    SetDialogProperty>Dialog1,,AlphaBlendValue,%OpacityValue%
    SetDialogProperty>Dialog1,MenuItem22,Checked,False
  Endif

END>SetOpacity


SRT>SetFontColor
  Let>Font_Color=%SetFontColor_Var_1%
  EditIniFile>%IniDir%\Stopwatch.ini,Settings,Font Color,%SetFontColor_Var_1%
  SetDialogObjectFont>Dialog1,Edit1,Font_Name,Font_Size,Font_Style,Font_Color
  SetDialogObjectFont>Dialog1,MSListBox1,Arial Black,12,1,Font_Color
END>SetFontColor


SRT>ExitScript

  //<--Start > Saved Time Function
  IF>TimerPaused=False
    IF>HasBeenReset=True
      Year>YY
      Month>MM
      Day>DD
      Hour>HH
      Min>NN
      Sec>SS
      GetTime>TheTime
      EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,%YY%/%MM%/%DD% %TheTime%
    ELSE
      Let>NumOfSecToAdd={Round(%NumOfSecPaused%)}
      ReadIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,SavedTimeRes
      VBEval>dateadd("s", "%NumOfSecPaused%", "%SavedTimeRes%"),NewTimeRes
      EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,%NewTimeRes%
    ENDIF

  ELSE
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Count,0
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Time,0
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Saved Time,0
    EditIniFile>%IniDir%\Stopwatch.ini,Settings,Lap Times,
  ENDIF
  //<--End > Saved Time Function
  Exit>1
END>ExitScript



/*
STOPWATCH16X16.ICO_DATA:
00000100020012120000010020008005000026000000101000000100200068040000A6050000280000001200000024000000010020000000000058050000000000000000000000000000000000005D4D4A001E94B300615957024B434000860000005606002E35292797283032DC263D36FE212E2EE8231E1FAD36000048012
C270000302E004F00000100929400342D2B003A302D005D504D018107000169504D00653C341A444B4B9D2E686CFE28979EFF2AC3CBFE25B6D6FE2BC6D4FE28A7AEFE216D72FF263E41C3400A033563000000341F1E012F39390052000000554847070DB5E40069504C224B5758C9289394FF28DCE4FA40EDF8FD4EF5FBFD4F
D6F7FE54EFFBFD4EF2FBFD3CEDF5FA23ACB1FF264F51EA38211E4A450000003F1008018A000000895C4D0213B6E30E5A605FAB2A9397FF26CEE6F44BE5ECFD4CE5E7FE4ADAE4FE4DE7E7FE4FE0E6FE55E4E9FD58E7F1FE43E3F8F523AFB8FE2C5052D73C2D2E2A0A98AD00267278052F6A7B009D3E27583C7F84FF1FD8DBF73
9D1F0FD3F7FCBFE4EC1C6FE47DDDDFE49CEDCFE4DD7DDFF58D6D8FE4DD7E4FD4ACDEEFE40F0F8F5259399FF3B3939900893A703279AA9040E7B9E1A617A7CA72B9EA7FD27E4F1F931F2F0FE2AAEE5FD3F76D2FF49D0D2FD4BDBD8FF4ED2DBFE5ACAD1FF4CE1E8FE42EDF2FE4AF0F8F92CC1CBFB356366D8A8000022531E1700
FF6C5359587F7FDB1CC0C3FE28EAF3FC2BDDE9FE2AF9F1FE28B2E8FE4072CEFE49B8C6FE4CC1C2FE51CED6FE41E3ECFE3BE7F2FE44EAF2FC32E6E8FA317E81FB533B39462B525A00D18A7783578585FB10A4C7FE28E1F4FD21E3E9FF2ADCEAFD22F9F1FF1EA5E0FF406C89FF2FB7B8FF30EDF7FF35E4EDFD36E7EFFE3FE6F0F
E2CCAF0F730818AFF624B41572B726300E19A897E5D8786F60BAAC3FE1FE6F4FE1CE0E7FE20DFEAFE0FE9F9FE46BBB3FF6F6052FF5E9894FF29EDF7FE2DE5F0FE30E3EBFD38E7F0FE26D3ECF635838BFF6D544D55246D6700FFC9B84B6E8A89D117B0B5FE12E4EDFB19DEE7FE0EE9F4FE43BBBDFE51A3A1FE2CB6BCFF44A8A9
FE5BAEACFE2BE2EBFE29E4ECFE2FE7F1FB21D1DAFB408183F9785E583F585C5B000E3B3C12989B9699369397FF00D4E1F80FE9F6FF41B5B6FE49B7B6FE10EAF5FE15E8F3FE12EBF7FE35C7CCFE35CCD1FE1FE7F4FF22E8F3F820ABB3FD5F7776CCAC60551A537A7C0051635E009E9B9143658888F505A9AFF80EC9ECFA2BB9D
0FF0CE3EBFD0FDDE9FE13DBE5FF16DBE5FE11E9F2FD18DBEFFF25C7EBFD0DCAD3F63C8A8CFF79807878A4857F001D9EAC04E1D1C805FFECEC07D3DAD28B518889FF009CABF600E2F2FA07E6F0FE0CE0EBFE0DE7EDFE11E3EDFD13E2ECFE11E1EEFC06BACAF4308B90FF808885C0B87A7E16A5837C00A8807504829797087372
6700592A2913BBBAB6A2629694FF18999EFF00B6C1FC00D4DBFE06BAE3FE00CEDDFE00C2CEFD0CABB2FE419695FF83908EC8A797932FBB697700A5847D01B47F71008D9F9E000000000156373600FFFFFF0EC3BBB86F7E8F8EEA5D9292FD2A898BFC1E7689FF298B92FC4E9494FD6D8989F889898796C1AAA31F948F8B00BC6
97701A5847D008289850097A4A200000C0000FFFFFF027778770064666500797573A6AFACA9FFD5D2D1F9BABDB4FEA7A49FFA8A8783FF756E6DCF846D6A0E685B5A008B858204BB6D79000000000000000000000000001F332200D7FCF6009496960471767500686D6AA3AFAFAEFEFFFFFFF8E1E0DFFFA8A8A6FA6D6D6DFE5F
6262CD95767215443D3F02787A7B0200000000000000000000000000000000000000008F8C8900818683014D535002656A6568979C99EDD8DCDCFDC1C9C7FC8E9393FC636667F96F70709488807D10727675018A888700000000000000000000000000FC1FC000F007C000E003C000C001C000C000C0008000C0008000C0000
000C0000000C0008000C0008000C000C000C000C001C000E003C000F007C000F80FC000F80FC000F80FC000280000001000000020000000010020000000000040040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000464646404040409F3B3B3BDF353535FF313131DF2E2E2E9F2C2C2C4000000000000000000000000000000000000000000000000000000000000000005656569F485D5FFF288D95FF1BA9B2FF15B8C3FF1AACB6FF228D95FF2F4647F
F3131319F0000000000000000000000000000000000000000000000006767679F4E7376FF1BAAB3FF2FCED7FF44E2EAFF1D91DFFF49E4ECFF37D4DDFF1CB5C0FF315E61FF3939399F000000000000000000000000000000007979794066787AFF1BA2ACFF1D91DFFF46EBF3FF46EBF3FF49ECF4FF4DEDF4FF50EDF5FF1D91DF
FF1CB2BCFF3E5455FF444444400000000000000000000000008383839F3C8E94FF22C1CBFF2CE5EFFF3636D4FF43EAF3FF43EAF3FF43EAF3FF46EBF3FF4BECF4FF30CED8FF2A8E95FF4F4F4F9F0000000000000000000000008F8F8FDF208F96FF23D6E0FF2CE5EFFF2CE5EFFF3636D4FF43EAF3FF39E9F2FF3DE9F2FF40EAF
3FF3BDFE7FF1CA0A9FF5B5B5BDF0000000000000000000000009A9A9AFF0F8890FF1D91DFFF22E4EEFF2CE5EFFF2CE5EFFF4D4D4DFF34E7F1FF34E7F1FF37E8F1FF1D91DFFF13A2ACFF666666FF000000000000000000000000A4A4A4DF22868CFF14D6E0FF18E2ECFF2CE5EFFF4D4D4DFF19E2EDFF7F877AFF34E7F1FF2DE6
EFFF2AD9E2FF1F97A0FF737373DF000000000000000000000000AEAEAE9F4E8E92FF0DAFB9FF22E4EEFF4D4D4DFF19E2EDFF19E2EDFF19E2EDFF7F877AFF2DE6EFFF1CBDC6FF3D8E93FF8080809F000000000000000000000000B8B8B840A4AFAFFF3D8687FF1D91DFFF0CDFEAFF0CDFEAFF0FE0EBFF13E0EBFF13E0EBFF1D9
1DFFF1A9199FF818F90FF8A8A8A4000000000000000000000000000000000BFBFBF9FAFB1AEFF3D8383FF07AAB3FF05CBD5FF1D91DFFF09CDD8FF0EB0B9FF198990FF7E989AFF9A9A9A9F000000000000000000000000000000000000000000000000C5C5C59FB0BABAFF578F92FF26797EFF0C6F76FF257C82FF508E93FF9C
A7A8FFA8A8A89F000000000000000000000000000000000000000000000000000000000000000090928FFFD2D2D2FFC7C7C7FFC2C2C2FFB1B1B1FF939393FF7E7E7EFF0000000000000000000000000000000000000000000000000000000000000000000000007E817DFFE8E8E8FFB8B8B8FF646464FF646464FF4B4B4BFF6
56565FF00000000000000000000000000000000000000000000000000000000000000000000000000000000787B76FFE8E8E8FF5E5E5EFF494949FF656565FF000000000000000000000000000000000000000000000000FFFF0000F01F0000E00F0000C0070000800300008003000080030000800300008003000080030000
80030000C0070000E00F0000F01F0000F01F0000F83F0000
*/


User avatar
JRL
Automation Wizard
Posts: 3435
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Stopwatch with Lap feature

Post by JRL » Fri May 06, 2022 8:48 pm

Looked this up this afternoon to steal er... I mean borrow the code portion that parses seconds into minutes, hours and days. Discovered that in Windows 10 the script as a whole no longer functions for me. The problem is that I'm not logged in as an admin. It seems you can't write to the C:\Program Files folder if you're not an admin. Everything for this script starts in that folder as it writes and stores data to an INI file it creates there. It is such a well written script that the fix is as simple as changing "Program Files" in the second line to "ProgramData".

To make this script work for non-admins the second line should read:
Let>IniDir=C:\ProgramData\Rains Stopwatch

Nine years old and still a great script Rain!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts