Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clock?

Status
Not open for further replies.

RadioX

IS-IT--Management
May 15, 2001
145
US
I need a clock that will display when I open a certain form. Basiclly what I am doing is writing a piece of time clock software. Yea I know they are prolly a dime a dozen but my parents want some custom features so I figured why the heck not ill just write one.

So basically I want a clock to display so when I click the punch in or punch out button it will insert that time into my database. I would like to pull the time from the computer if that is possible.

Any way any solution is a possibility for me.

Thanks
Ron
 
If you have a text box on the form that you want to use to display your clock just add a timer and put the system time into that text box.
1) Add a timer to the form. Set the interval depending on how accurate you want to be (if you are going to display seconds you want an interval less than 1000 which is one second, if you are only going to display hours and minutes you can set the interval to 60000 which is one minute). Make sure the timer control's Enabled property is set to true.
2) Double click the new timer on your form. This will open the code window where you will see this

Private Sub Timer1_Timer()

End Sub

Add this line of code to the procedure (assuming you want to display the time in a text box called txtClock).

txtClock.Text = Format(Now(), "Short Time")

So the procedure will look like this:

Private Sub Timer1_Timer()
txtClock.Text = Format(Now(), "Short Time")
End Sub

that should give you your clock on the screen. From there you can save the time in the textbox into the database when one of your buttons is clicked. Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Ron,

I have exactly what you need, no charge. I have developed a full blown time clock system for multi-million dollar retail corporation. I will give you the source code and everything. The only things you will have to change are the way the time gets stamped to a file, and some of the fields that are contained inside each record when somebody clocks in our out. Currently the program saves the following infomation:

Store Number.......Where is the Clock Located?
(we have 16 retail stores, each
has a unique number assigned to
it)
Time Clock Number..What Time Clock inside given location
(each store has muliple clocks
each one has unique number)
Employee Number....Unique Number assigned to each
employee for idenification
Todays Date........When the person clocks in the program
captures the current date
Current Time.......When the employee clocks in the
program caputures the current time

The current date and time are captured from the system date and time on the local computer.

With my application we use a keyboard that has a "credit card" type reader on it. Each employee has a special ID badge that has a special magnetic strip that contains the employees ID number. When the employee wants to clock in or out, all they have to do is swipe their ID badge through the badge reader ("credit card" reader) And it captures the employees number in a text box. Built into the card is a carriage return-line feed (like pressing enter on the keyboard). So I have a command button on the form, hidden that is set as the default. When the badge is swiped the badge data is put into the text box, and the command button is pressed caputuring all of the data needed to process the employees clock in or out (listed above). For your purposes, keep everything the same for entry, just change what the program is doing. Let the user enter their name in the textbox, and have them hit enter to accept the time. So the code below will need slight modification to allow the user to input their name. Currently if the text box does not start with a certain character (the badge has a special character at the start and end of the ID number - which is the same on all). For error handling if the swipe did not leave both characters, it says error reading badge. You need to take that out, remove the location and clock number from the program, and make a visable command button for the user to see and you should have it! Here is the code (note that their is a code module for this application!):

Code Module:
Code:
Option Explicit

Type BadgeID
    StoreNo As String * 2      'enviromental variable
    Dummy1 As String * 1
    ClockNo As String * 2      'enviromental variable
    Dummy2 As String * 1
    EmployeeID As String * 5   'from badge swipe
    Dummy3 As String * 1
    Date As String * 7         'computer date
    Dummy4 As String * 1
    Time As String * 6         'computer time
    EndofRec As String * 2     'CR/LF  ( CHR13 & CHR10 )
End Type

Type LastBadge
    EmpID As String * 5
    LastDate As String * 7
    LastTime As String * 6
End Type

Public BadgeTable(500) As String, StoreNo As String, ClockNo As String
Public Badges As LastBadge




Main Program



Code:
Private Sub cmdClick_Click()
    '*************************************************
    '**********     Declare Variables     ************
    '*************************************************
    
    Dim ClockRecord As BadgeID
    Dim JDate As String
    Dim Date1 As Date
    Dim MyYear As Integer
    Dim EmpID As String
    Dim RightNow, Hours, Minutes, Seconds
    Dim BadgeRecord As Integer
                          
    '**************************************************    
    '**********     Setup Variables    ****************
    '**************************************************
    
    RightNow = Now
    Hours = Right("00" + Trim(Str(Hour(RightNow))), 2)
    Minutes = Right("00" + Trim(Str(Minute(RightNow))), 2)
    Seconds = Right("00" + Trim(Str(Second(RightNow))), 2)
    EmpID = Left(Right(BadgeSwipe.Text, 6), 5)
    MyYear = Val(Right(Format(Date, "Long Date"), 4))
    Date1 = "12/31/" + Str(MyYear - 1)
    JDate = DateDiff("d", Date1, Now)
                   
    '**************************************************
    '**********     Validating Badge Swipe     ********
    '**************************************************
       
    If Left(BadgeSwipe.Text, 1) <> &quot;@&quot; Then
        Result = MsgBox(&quot;Error Reading Badge -- Press ENTER to Try Again!&quot;, vbOKOnly, &quot;ERROR&quot;)
        BadgeSwipe.Text = &quot;&quot;
        BadgeSwipe.SetFocus
        Exit Sub
    End If
    
    If Right(BadgeSwipe.Text, 1) <> &quot;#&quot; Then
        Result = MsgBox(&quot;Error Reading Badge -- Press ENTER to Try Again!&quot;, vbOKOnly, &quot;ERROR&quot;)
        BadgeSwipe.Text = &quot;&quot;
        BadgeSwipe.SetFocus
        Exit Sub
    End If
    
    BadgeRecord = 0
    For i = 1 To UBound(BadgeTable)
        If BadgeTable(i) = EmpID Then
            BadgeRecord = i
            Exit For
        End If
    Next
    If BadgeRecord > 0 Then
        Open &quot;c:\stores\timeclck\data\badges&quot; For Random As #1 Len = Len(Badges)
        Get #1, BadgeRecord, Badges
    End If
    
    If Right(BadgeSwipe.Text, 1) = &quot;#&quot; Then
        
    '**************************************************
    '**********     Create Clock File     *************
    '**************************************************
    
    ClockRecord.EmployeeID = EmpID
    ClockRecord.EndofRec = Chr(13) + Chr(10)
    ClockRecord.StoreNo = StoreNo
    ClockRecord.ClockNo = ClockNo
    ClockRecord.Date = LTrim(Str(MyYear)) + JDate
    ClockRecord.Time = Hours & Minutes & Seconds
    ClockRecord.Dummy1 = &quot; &quot;
    ClockRecord.Dummy2 = &quot; &quot;
    ClockRecord.Dummy3 = &quot; &quot;
    ClockRecord.Dummy4 = &quot; &quot;
    
    '**************************************************
    '**********     Open and Write Clock File     *****
    '**************************************************
    
    FileName = &quot;c:\stores\timeclck\data\clck&quot; + StoreNo + Right(ClockNo, 1) + &quot;.&quot; + JDate
    Open FileName For Random As #1 Len = Len(ClockRecord)
    FileLength = LOF(1)
    LastRecord = FileLength / Len(ClockRecord) + 1
    Put #1, LastRecord, ClockRecord
    Close
    BadgeSwipe.Text = &quot;&quot;



End Sub
Private Sub Form_Load()
    Open &quot;c:\stores\timeclck\data\badges&quot; For Random As #1 Len = Len(Badges)
    FileLength = LOF(1)
    LastRecord = FileLength / Len(Badges)
    For i = 1 To LastRecord
        Get #1, i, Badges
        BadgeTable(i) = Badges.EmpID
    Next
    Close


    '***************LOAD ENVIROMENT VARIABLES
    '****************FOR STORE NUMBER AND CLOCK NUMBER
  
    StoreNo = Environ(&quot;STORENUM&quot;)
    ClockNo = Environ(&quot;CLOCK&quot;)

End Sub

Private Sub Timer1_Timer()
    If lblTime(1).Caption <> CStr(Time) Then
        lblTime(1).Caption = Time
    
        End If


    '***************CLOSE PROGRAM AT DAY END    

    lbldate.Caption = Format(Date, &quot;Long Date&quot;)
    If Time = &quot;12:00:00 AM&quot; Then
        End
        
        End If
       
End Sub
 
Ooops Sorry Ron, I ment to add that this section of code:

Code:
Private Sub Timer1_Timer()
    If lblTime(1).Caption <> CStr(Time) Then
        lblTime(1).Caption = Time
    
        End If


    '***************CLOSE PROGRAM AT DAY END    

    lbldate.Caption = Format(Date, &quot;Long Date&quot;)
    If Time = &quot;12:00:00 AM&quot; Then
        End
        
        End If
       
End Sub

Will display the current time on your form in a label! Hope all of this code helps your project out! Drop a thread updating your developmental progress, tell us how its working out for you! Later!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top