473,382 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Clock script

I wanted to add a clock feature to a form for both Start Time and End Time fields. I followed the instructions from the Help files to make the Start Time work smoothly. The Help files only gave the code for one field, however, and I need two. Following is the OnCurrent Event Procedure for the Start Time field.

All of my controls for the End Time clock feature are exactly the same with a "2" behind them.

The question is: Do I need to add lines of code in the following code to perform the same tasks for the End Time field, or do I copy and paste the exact code and go through and correct the control names to be ending with 2? If the latter, there are a few items in the code I need to know if I should update as well.

1-oCtl (what is this? Do I need to rename it oCtl2 for the End Time control?)
2-fIncrement (don't know what this is, either. Do I rename to fIncrement2?)
3-iChange(again, don't know what it is for. Name it iChange2?)

I assume I can rename the second copy of code to ClockChangeTime2 as well as ClockFlipAMPM to ClockFlipAMPM2, ClockAddLeadingZeros to ClockAddLeadingZeros2, ClockLoadDate to ClockLoadDate2 and ClockSaveDate to ClockSaveDate2????

Expand|Select|Wrap|Line Numbers
  1.  '// This routine will change the time part + or - 1.
  2. Public Sub ClockChangeTime(oCtl As TextBox, fIncrement As Boolean)
  3.     Dim iChange As Integer
  4.  
  5.     'See if we are adding or subtracting.
  6.     If fIncrement Then
  7.         iChange = 1
  8.     Else
  9.         iChange = -1
  10.     End If
  11.  
  12.     'Find out what part of the time we are supposed to act on.
  13.     Select Case oCtl.Name
  14.         'Check for the hour.
  15.         Case Is = "txtHour"
  16.             'Check to see if we need to change am/pm.
  17.             If txtHour = 11 And iChange = 1 Then ClockFlipAMPM
  18.             If txtHour = 12 And iChange = -1 Then ClockFlipAMPM
  19.  
  20.             'Change the hour.
  21.             txtHour = txtHour + iChange
  22.  
  23.             'See if we need to roll over.
  24.             If txtHour <= 0 Then
  25.                 txtHour = 12
  26.             ElseIf txtHour >= 13 Then
  27.                 txtHour = 1
  28.             End If
  29.  
  30.         'Check for the minutes.
  31.         Case Is = "txtMin"
  32.             txtMin = txtMin + iChange
  33.  
  34.             'See if we need to roll over.
  35.             If txtMin <= -1 Then
  36.                 txtMin = 59
  37.                 ClockChangeTime txtHour, False
  38.             ElseIf txtMin >= 60 Then
  39.                 txtMin = 0
  40.                 ClockChangeTime txtHour, True
  41.             End If
  42.  
  43.         'Check for the seconds.
  44.         Case Is = "txtSec"
  45.             txtSec = txtSec + iChange
  46.  
  47.             'See if we need to roll over.
  48.             If txtSec <= -1 Then
  49.                 txtSec = 59
  50.                 ClockChangeTime txtMin, False
  51.             ElseIf txtSec >= 60 Then
  52.                 txtSec = 0
  53.                 ClockChangeTime txtMin, True
  54.             End If
  55.     End Select
  56.  
  57.     'Be sure we have 0's in front.
  58.     ClockAddLeadingZeros
  59.  
  60.     'Save the date back to the recordset.
  61.     ClockSaveDate
  62.  
  63.     'Let's refresh in case the user is holding down the button.
  64.     DoEvents
  65. End Sub
  66.  
  67. '// Adds 0's to the front of the time parts.
  68. Private Sub ClockAddLeadingZeros()
  69.      If Len(txtHour) <> 2 Then txtHour = "0" & txtHour
  70.      If Len(txtMin) <> 2 Then txtMin = "0" & txtMin
  71.      If Len(txtSec) <> 2 Then txtSec = "0" & txtSec
  72. End Sub
  73.  
  74. '// Used to write the date back to the form value.
  75. Private Sub ClockSaveDate()
  76.     If cboAMPM = "PM" And txtHour <> 12 Then
  77.         [Start Time].Value = TimeSerial(txtHour + 12, txtMin, txtSec)
  78.     Else
  79.         [Start Time].Value = TimeSerial(txtHour, txtMin, txtSec)
  80.     End If
  81. End Sub
  82.  
  83. '// Called to initalize the textboxes with the date.
  84. '// Can be called on oncurrent event to sync with form.
  85. '// recordset movement
  86. Private Sub ClockLoadDate(sDate As String)
  87.     'Check to see if we have a valid date.
  88.     If IsDate(sDate) Then
  89.         'Load the hour.
  90.         txtHour = Hour(sDate)
  91.         If txtHour = 0 Then txtHour = 12
  92.         If txtHour > 12 Then txtHour = txtHour - 12
  93.  
  94.         'Load the minutes and seconds.
  95.         txtMin = Minute(sDate)
  96.         txtSec = Second(sDate)
  97.  
  98.         'Load the AM/PM.
  99.         If Hour(sDate) < 12 Then
  100.             cboAMPM.Value = "AM"
  101.         Else
  102.             cboAMPM.Value = "PM"
  103.         End If
  104.  
  105.         'Be sure we have 0's in front.
  106.         ClockAddLeadingZeros
  107.     Else
  108.         'Not a valid date; set a default.
  109.         txtHour = "12"
  110.         txtMin = "00"
  111.         txtSec = "00"
  112.         cboAMPM = "AM"
  113.     End If
  114. End Sub
  115.  
  116. '// Used to flip am/pm when rolling over between the 2.
  117. Sub ClockFlipAMPM()
  118.     If cboAMPM.Value = "AM" Then
  119.        cboAMPM.Value = "PM"
  120.     Else
  121.         cboAMPM.Value = "AM"
  122.     End If
  123. End Sub
  124.  



Also, how do I write this code and save it for future use in other databases? I'm sure I'll use this feature often and as little as I know about VBA I'd like to avoid having to re-do all of this.

Any help is appreciated.
Mar 16 '07 #1
5 2544
BTW, I do not have a Seconds field but did not know which lines of code I could delete. Do I even need to delete andy Seconds code?
Mar 16 '07 #2
Rabbit
12,516 Expert Mod 8TB
What are you trying to accomplish?
What do you mean by adding a clock feature for Start Time and End Time?
Mar 16 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
What are you trying to accomplish?
What do you mean by adding a clock feature for Start Time and End Time?
If you are talking about an activeX clock where the user selects a time and it is passed to the textbox then you will need a separate instance of the clock for each textbox.

Mary
Mar 16 '07 #4
I did not know there is an ActiveX clock. I do know how to use the ActiveX Calendar control. Is it the same?

The code I referenced is directly from the Access help files for adding a "digital" clock feature to a form for a single text box. I need it for TWO text boxes, a start and stop time for an Employee Time Card database. Since I'm not familiar with VBA, I wasn't sure how to modify the code I downloaded to work for both text boxes.
Mar 20 '07 #5
ADezii
8,834 Expert 8TB
I wanted to add a clock feature to a form for both Start Time and End Time fields. I followed the instructions from the Help files to make the Start Time work smoothly. The Help files only gave the code for one field, however, and I need two. Following is the OnCurrent Event Procedure for the Start Time field.

All of my controls for the End Time clock feature are exactly the same with a "2" behind them.

The question is: Do I need to add lines of code in the following code to perform the same tasks for the End Time field, or do I copy and paste the exact code and go through and correct the control names to be ending with 2? If the latter, there are a few items in the code I need to know if I should update as well.

1-oCtl (what is this? Do I need to rename it oCtl2 for the End Time control?)
2-fIncrement (don't know what this is, either. Do I rename to fIncrement2?)
3-iChange(again, don't know what it is for. Name it iChange2?)

I assume I can rename the second copy of code to ClockChangeTime2 as well as ClockFlipAMPM to ClockFlipAMPM2, ClockAddLeadingZeros to ClockAddLeadingZeros2, ClockLoadDate to ClockLoadDate2 and ClockSaveDate to ClockSaveDate2????

Expand|Select|Wrap|Line Numbers
  1.  '// This routine will change the time part + or - 1.
  2. Public Sub ClockChangeTime(oCtl As TextBox, fIncrement As Boolean)
  3.     Dim iChange As Integer
  4.  
  5.     'See if we are adding or subtracting.
  6.     If fIncrement Then
  7.         iChange = 1
  8.     Else
  9.         iChange = -1
  10.     End If
  11.  
  12.     'Find out what part of the time we are supposed to act on.
  13.     Select Case oCtl.Name
  14.         'Check for the hour.
  15.         Case Is = "txtHour"
  16.             'Check to see if we need to change am/pm.
  17.             If txtHour = 11 And iChange = 1 Then ClockFlipAMPM
  18.             If txtHour = 12 And iChange = -1 Then ClockFlipAMPM
  19.  
  20.             'Change the hour.
  21.             txtHour = txtHour + iChange
  22.  
  23.             'See if we need to roll over.
  24.             If txtHour <= 0 Then
  25.                 txtHour = 12
  26.             ElseIf txtHour >= 13 Then
  27.                 txtHour = 1
  28.             End If
  29.  
  30.         'Check for the minutes.
  31.         Case Is = "txtMin"
  32.             txtMin = txtMin + iChange
  33.  
  34.             'See if we need to roll over.
  35.             If txtMin <= -1 Then
  36.                 txtMin = 59
  37.                 ClockChangeTime txtHour, False
  38.             ElseIf txtMin >= 60 Then
  39.                 txtMin = 0
  40.                 ClockChangeTime txtHour, True
  41.             End If
  42.  
  43.         'Check for the seconds.
  44.         Case Is = "txtSec"
  45.             txtSec = txtSec + iChange
  46.  
  47.             'See if we need to roll over.
  48.             If txtSec <= -1 Then
  49.                 txtSec = 59
  50.                 ClockChangeTime txtMin, False
  51.             ElseIf txtSec >= 60 Then
  52.                 txtSec = 0
  53.                 ClockChangeTime txtMin, True
  54.             End If
  55.     End Select
  56.  
  57.     'Be sure we have 0's in front.
  58.     ClockAddLeadingZeros
  59.  
  60.     'Save the date back to the recordset.
  61.     ClockSaveDate
  62.  
  63.     'Let's refresh in case the user is holding down the button.
  64.     DoEvents
  65. End Sub
  66.  
  67. '// Adds 0's to the front of the time parts.
  68. Private Sub ClockAddLeadingZeros()
  69.      If Len(txtHour) <> 2 Then txtHour = "0" & txtHour
  70.      If Len(txtMin) <> 2 Then txtMin = "0" & txtMin
  71.      If Len(txtSec) <> 2 Then txtSec = "0" & txtSec
  72. End Sub
  73.  
  74. '// Used to write the date back to the form value.
  75. Private Sub ClockSaveDate()
  76.     If cboAMPM = "PM" And txtHour <> 12 Then
  77.         [Start Time].Value = TimeSerial(txtHour + 12, txtMin, txtSec)
  78.     Else
  79.         [Start Time].Value = TimeSerial(txtHour, txtMin, txtSec)
  80.     End If
  81. End Sub
  82.  
  83. '// Called to initalize the textboxes with the date.
  84. '// Can be called on oncurrent event to sync with form.
  85. '// recordset movement
  86. Private Sub ClockLoadDate(sDate As String)
  87.     'Check to see if we have a valid date.
  88.     If IsDate(sDate) Then
  89.         'Load the hour.
  90.         txtHour = Hour(sDate)
  91.         If txtHour = 0 Then txtHour = 12
  92.         If txtHour > 12 Then txtHour = txtHour - 12
  93.  
  94.         'Load the minutes and seconds.
  95.         txtMin = Minute(sDate)
  96.         txtSec = Second(sDate)
  97.  
  98.         'Load the AM/PM.
  99.         If Hour(sDate) < 12 Then
  100.             cboAMPM.Value = "AM"
  101.         Else
  102.             cboAMPM.Value = "PM"
  103.         End If
  104.  
  105.         'Be sure we have 0's in front.
  106.         ClockAddLeadingZeros
  107.     Else
  108.         'Not a valid date; set a default.
  109.         txtHour = "12"
  110.         txtMin = "00"
  111.         txtSec = "00"
  112.         cboAMPM = "AM"
  113.     End If
  114. End Sub
  115.  
  116. '// Used to flip am/pm when rolling over between the 2.
  117. Sub ClockFlipAMPM()
  118.     If cboAMPM.Value = "AM" Then
  119.        cboAMPM.Value = "PM"
  120.     Else
  121.         cboAMPM.Value = "AM"
  122.     End If
  123. End Sub
  124.  



Also, how do I write this code and save it for future use in other databases? I'm sure I'll use this feature often and as little as I know about VBA I'd like to avoid having to re-do all of this.

Any help is appreciated.
The code you are attempting to reproduce reflects Actual Flight Arrival Times which the User can enter directly into an Arrival Time Text Box, or produce using several 'Spin Button' type effects to enter Hours. Minutes, Seconds, and AM/PM Values. The result of all this interaction is to store the Arrival Time in a Date/Time Field and convert/reflect the proper value for each Current Record being shown. If you also require an End Time Field, you would have to duplicate much of this functionality in order to accomplish this. Unless you are proficient in VB coding, I suggest you use 2 Text Boxes with the appropriate Input Mask and Format Properties set, and bind them to the appropriate Fields as in:
Expand|Select|Wrap|Line Numbers
  1. Input Mask: 99:00:00\ >LL;0;_
  2. Format    : hh:nn:ss AM/PM
Mar 21 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Gino Elloso - Philippines | last post by:
Hello, I made a webpage ( @ Geocities Free Webpages ) that contains a mousetrail clock script. I simply copied the script ( including all html tags ) exactly as it was from a source webpage (...
3
by: Szabolcs Nagy | last post by:
I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i...
1
by: s.shahzaib.ali | last post by:
I want to make analog clock skin of windows media player so how can i roteate the layer upto 360 degrees with the help of javascript please tell me iam very anxious about it. iam the first and only...
7
by: ruca | last post by:
How can I show a run time clock in my ASP .NET page???? Can anyone have any code to show that? I have a javscript file that have all necessary code for that, but I'm using VB in my ASPX page and I...
3
by: mistral | last post by:
Here is javscript clock: http://javascript.internet.com/time-date/mousetrailclock.html which I want adjust a little: 1. I want replace the days of week/year/date in external circle with just...
12
by: cenktarhancenk | last post by:
is there a way to display a ticking clock in a web page using javascript? but not in a textbox, rather as text that i can change the style, font etc. cenk tarhan
7
by: Daz | last post by:
Hi everyone. I am trying to find out how I can create a real time clock, which knows when to set itself backwards or forwards 1 hour. The clock will work for various timezones. Some of which...
3
w33nie
by: w33nie | last post by:
I'd like to put a clock on my web site, that shows the time where I am, not where the user is. I found a regular clock with google, that shows the time of the user's system clock, so I thought it...
1
by: ANB8503 | last post by:
Hello, I have created the below script; however, it's not showing in the box like it should... Help please!! I am running out of time to submit this assignment! Thanks in advance!! ...
7
Frinavale
by: Frinavale | last post by:
This whole thing started when I wanted to display list items in a circle...it just looked way too much like a clock. So for fun I started to create a JavaScript Analog clock. I was wondering how...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.