Description

A stop-watch timer I made to keep track of time, primarily to see how much time I’m wasting or how much time something takes to do. Double click the time to start the stop watch at a specific time, double click description to edit, press enter to save.

Source Code

VERSION 5.00
Begin VB.Form frmMain 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Timer"
   ClientHeight    =   1545
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   2805
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   1545
   ScaleWidth      =   2805
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtTime 
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   24
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   555
      Left            =   480
      TabIndex        =   5
      Top             =   360
      Visible         =   0   'False
      Width           =   1890
   End
   Begin VB.TextBox txtInfo 
      BorderStyle     =   0  'None
      Height          =   195
      Left            =   120
      TabIndex        =   4
      Top             =   120
      Visible         =   0   'False
      Width           =   2610
   End
   Begin VB.Timer tmrTime 
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   3240
      Top             =   120
   End
   Begin VB.CommandButton cmdStop 
      Caption         =   "Stop"
      Enabled         =   0   'False
      Height          =   495
      Left            =   120
      TabIndex        =   3
      Top             =   960
      Width           =   1095
   End
   Begin VB.CommandButton cmdStart 
      Caption         =   "Start"
      Height          =   495
      Left            =   1560
      TabIndex        =   2
      Top             =   960
      Width           =   1095
   End
   Begin VB.Label lblTime 
      AutoSize        =   -1  'True
      Caption         =   "00:00:00"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   24
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   555
      Left            =   480
      TabIndex        =   1
      Top             =   360
      Width           =   1890
   End
   Begin VB.Label lblInfo 
      AutoSize        =   -1  'True
      Caption         =   "Amount of time you've been working:"
      Height          =   195
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   2610
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Written by Me, because I'm great

Option Explicit
Dim intSeconds As Integer, intMinutes As Integer, intHours As Integer

Private Sub cmdStart_Click()
    cmdStart.Enabled = False
    cmdStop.Enabled = True
    tmrTime.Enabled = True
End Sub

Private Sub cmdStop_Click()
    cmdStart.Enabled = True
    cmdStop.Enabled = False
    tmrTime.Enabled = False
End Sub

Private Sub lblInfo_DblClick()
    txtInfo.Text = lblInfo.Caption
    txtInfo.Visible = True
End Sub

Private Sub lblTime_DblClick()
    If tmrTime.Enabled = True Then
        Call MsgBox("You must stop the timer to change the time.", vbInformation, "Mr. Timer")
    Else
        txtTime.Text = lblTime.Caption
        txtTime.Visible = True
    End If
End Sub

Private Sub txtInfo_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        ' If someone puts nothing, since the label auto-sizes
        ' then they could accidently make it to where nothing
        ' can be clicked on to fix it later. So we set it to
        ' something so at least they can click it.
        
        If txtInfo.Text = "" Then
            txtInfo.Text = "(None)"
        End If
        
        lblInfo.Caption = txtInfo.Text
        txtInfo.Visible = False
    End If
End Sub

Private Sub txtTime_KeyPress(KeyAscii As Integer)
    On Error Resume Next
    
    Dim strHours As String, strMinutes As String, strSeconds As String
    Dim intTemp As Integer
    
    If KeyAscii = 13 Then
        If txtTime.Text = "" Then
            txtTime.Text = lblTime.Caption
        End If

        ''
        '' Check syntax
        ''
        
        If Mid(txtTime.Text, 3, 1) <> ":" Or Mid(txtTime.Text, 6, 1) <> ":" Then
            Call MsgBox("Incorrect format, it must be ""hh:mm:ss""!", vbInformation, "Mr. Timer")
            Exit Sub
        End If
        
        strHours = Mid(txtTime.Text, 1, 2)
        intTemp = Int(strHours)
        If intTemp < 0 Then
            Call MsgBox("Incorrect format, it must be ""hh:mm:ss""!" & vbCrLf & vbCrLf & "Your hours are incorrect.", vbInformation, "Mr. Timer")
            Exit Sub
        End If
        
        strMinutes = Mid(txtTime.Text, 4, 2)
        intTemp = Int(strMinutes)
        If intTemp < 0 Or intTemp > 59 Then
            Call MsgBox("Incorrect format, it must be ""hh:mm:ss""!" & vbCrLf & vbCrLf & "Your minutes are incorrect.", vbInformation, "Mr. Timer")
            Exit Sub
        End If
        
        strSeconds = Mid(txtTime.Text, 7, 2)
        intTemp = Int(strSeconds)
        If intTemp < 0 Or intTemp > 59 Then
            Call MsgBox("Incorrect format, it must be ""hh:mm:ss""!" & vbCrLf & vbCrLf & "Your seconds are incorrect.", vbInformation, "Mr. Timer")
            Exit Sub
        End If
        
        intHours = Int(strHours)
        intMinutes = Int(strMinutes)
        intSeconds = Int(strSeconds)
        
        lblTime.Caption = txtTime.Text
        txtTime.Visible = False
    End If
End Sub

Private Sub tmrTime_Timer()
    Dim strHours As String, strMinutes As String, strSeconds As String

    If intMinutes = 59 And intSeconds = 59 Then
        intMinutes = 0
        intSeconds = 0
        intHours = intHours + 1
    End If
    
    If intSeconds = 59 Then
        intSeconds = 0
        intMinutes = intMinutes + 1
    Else
        intSeconds = intSeconds + 1
    End If
    
    strHours = Trim(Str(intHours))
    If intHours < 10 Then
        strHours = "0" & strHours
    End If
    
    strMinutes = Trim(Str(intMinutes))
    If intMinutes < 10 Then
        strMinutes = "0" & strMinutes
    End If
    
    strSeconds = Trim(Str(intSeconds))
    If intSeconds < 10 Then
        strSeconds = "0" & strSeconds
    End If
    
    lblTime.Caption = strHours & ":" & strMinutes & ":" & strSeconds
End Sub

Hi I couldn’t get this to work. Can you help me?