By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,829 Members | 673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,829 IT Pros & Developers. It's quick & easy.

Entering Times

PhilOfWalton
Expert 100+
P: 1,430
Background:
We are running a Half Marathon event, and I want to enter the elapsed times as painlessly as possible. By and large, results come in in order of finishing, so the next person to finish will have a time greater or equal to the previous runner.

I select the runner whose time I want to enter, and let's say the time of the previous runner was 1:23:40
So by default I set the current runner's time the same 1:23:40
Now lets say his actual finishing time is 1:25:21.
What I want to do is just type 521 (no colons) and have that overwriting the 3:40. (3 minutes 40 seconds)

I have a procedure that works to give the correct results, but it fires on the AfterUpdate of the Text Box where I enter the 521. I can give details if relevant. With this routine, entering 1 or 2 numbers alters the seconds; entering 3 or 4 numbers alters minutes and seconds; entering 5 or 6 numbers alters hours minutes and seconds.

Although it works perfectly, the operator can't see what is happening.

What I think I want is to run a procedure on the OnChange of the text box to overlay the numbers. So as each number is entered, the previously entered number must move 1 place to the left, avoiding the colons.

so I envisage something like this:-
Expand|Select|Wrap|Line Numbers
  1. Number Entered     Display
  2.                    01:23:40
  3.        5           01:23:45
  4.        2           01:23:52
  5.        1           01:25:21
  6.  

Any ideas please?

Phil
May 14 '17 #1

✓ answered by NeoPa

Hi Phil.

More details to follow later but the form has a TextBox called [txtTest] and the code below does what you need :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private strLastUsed As String
  5. Private lngLastPos As Long
  6.  
  7. Private Sub Form_Open(Cancel As Integer)
  8.     strLastUsed = "00:00:00"
  9. End Sub
  10.  
  11. Private Sub txtTest_Enter()
  12.     Me.txtTest = Right(strLastUsed, IIf(strLastUsed Like "0*", 7, 8))
  13.     lngLastPos = 0
  14. End Sub
  15.  
  16. Private Sub txtTest_KeyDown(KeyCode As Integer, Shift As Integer)
  17.     If Shift <> 0 Then Exit Sub
  18.     Select Case KeyCode
  19.     Case vbKey0 To vbKey9
  20.         Call ProcessKey(Asc("0") + KeyCode - vbKey0)
  21.         KeyCode = 0
  22.     Case vbKeyNumpad0 To vbKeyNumpad9
  23.         Call ProcessKey(Asc("0") + KeyCode - vbKeyNumpad0)
  24.         KeyCode = 0
  25.     End Select
  26. End Sub
  27.  
  28. Private Sub ProcessKey(intASC As Integer)
  29.     Const conPos As String = "8775544221"
  30.     Dim lngPos As Long, lngFrom As Long, lngTo As Long
  31.  
  32.     For lngPos = lngLastPos To 1 Step -1
  33.         lngFrom = CLng(Mid(conPos, lngPos * 2 - 1, 1))
  34.         lngTo = CLng(Mid(conPos, lngPos * 2, 1))
  35.         Mid(strLastUsed, lngTo, 1) = Mid(strLastUsed, lngFrom, 1)
  36.     Next lngPos
  37.     Mid(strLastUsed, 8, 1) = Chr(intASC)
  38.     Me.txtTest = Right(strLastUsed, IIf(strLastUsed Like "0*", 7, 8))
  39.     lngLastPos = lngLastPos + 1
  40. End Sub

Share this Question
Share on Google+
6 Replies


zmbd
Expert Mod 5K+
P: 5,397
Just to be clear:
You have an unbound textbox that you're entering the new time in?
May 14 '17 #2

PhilOfWalton
Expert 100+
P: 1,430
Yes the unbound textbox is InputElapsed1

What happens is on the OnCurrant of the form, I run this

Expand|Select|Wrap|Line Numbers
  1. Sub PartialTime()
  2.  
  3.     'Highlight and attempt to predict time of next finisher
  4.     Dim StartTime As Date
  5.  
  6.     StartTime = Nz(DLookup("StartTime", "TblJoinRaceYear", "RaceID = " & RaceID & " AND YearID = " & DMax("YearID", "TblJoinRaceYear")))
  7.  
  8.     FinishTime.SetFocus
  9.  
  10.     If IsNull(FinishTime) Then
  11.         FTime = Nz(DMax("FinishTime", "QGroupFinishTime", "RaceGroupID = " & CboRaceGroupID))
  12.         If FTime = 0 Then                           ' No finishers for this race so use start time
  13.             FTime = Nz(DLookup("StartTime", "TblJoinRaceYear", "RaceID = " & RaceID & " AND YearID = " & DMax("YearID", "TblJoinRaceYear")))
  14.             FinishTime = FTime
  15.             FinishTime.SetFocus
  16.             FinishTime.SelStart = 0
  17.             FinishTime.SelLength = 8
  18.         Else
  19.             FinishTime = FTime
  20.             FinishTime.SetFocus
  21.             FinishTime.SelStart = 6
  22.             FinishTime.SelLength = 2
  23.         End If
  24.         If Second(FTime) > 57 Then                ' Probably next minute
  25.             FinishTime.SelStart = 3
  26.             FinishTime.SelLength = 5
  27.         End If
  28.     End If
  29.  
  30.     InPutElapsed = CStr(CDate(DateDiff("s", StartTime, FinishTime) / 86400))
  31.     InputElapsed1 = InPutElapsed
  32.  
  33. End Sub
  34.  
So StartTime looks up the starting time of the race.
FinishTime is a bound textbox to enter the finishing time.
FTime finds the maximum finishing time for runners in that group (Half marathon or Fun Run).

As I mentioned, I have one routine that works. The SelStarts and SelLength attempt to position the cursor so that one can enter just seconds or seconds & minutes, but in the latter case you also have to type a colon - real pain.

The unbound Field InputElapsed shows the elapsed time and AfterUpdate Calculates & saves the FinishTime if I chhose to enter the elapsed time rather than the finishing time.

InputElapsed1 (the unbound field mentioned earlier) is the new field I am trying to sort out, and initially displays the same elapsed time as InputElapsed.

So the bit in my first post, where it is marked Display, is what I want to see in InputElapsed1.

Hope that clarifies things

Thanks

Phil
May 14 '17 #3

NeoPa
Expert Mod 15k+
P: 31,418
Hi Phil.

More details to follow later but the form has a TextBox called [txtTest] and the code below does what you need :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private strLastUsed As String
  5. Private lngLastPos As Long
  6.  
  7. Private Sub Form_Open(Cancel As Integer)
  8.     strLastUsed = "00:00:00"
  9. End Sub
  10.  
  11. Private Sub txtTest_Enter()
  12.     Me.txtTest = Right(strLastUsed, IIf(strLastUsed Like "0*", 7, 8))
  13.     lngLastPos = 0
  14. End Sub
  15.  
  16. Private Sub txtTest_KeyDown(KeyCode As Integer, Shift As Integer)
  17.     If Shift <> 0 Then Exit Sub
  18.     Select Case KeyCode
  19.     Case vbKey0 To vbKey9
  20.         Call ProcessKey(Asc("0") + KeyCode - vbKey0)
  21.         KeyCode = 0
  22.     Case vbKeyNumpad0 To vbKeyNumpad9
  23.         Call ProcessKey(Asc("0") + KeyCode - vbKeyNumpad0)
  24.         KeyCode = 0
  25.     End Select
  26. End Sub
  27.  
  28. Private Sub ProcessKey(intASC As Integer)
  29.     Const conPos As String = "8775544221"
  30.     Dim lngPos As Long, lngFrom As Long, lngTo As Long
  31.  
  32.     For lngPos = lngLastPos To 1 Step -1
  33.         lngFrom = CLng(Mid(conPos, lngPos * 2 - 1, 1))
  34.         lngTo = CLng(Mid(conPos, lngPos * 2, 1))
  35.         Mid(strLastUsed, lngTo, 1) = Mid(strLastUsed, lngFrom, 1)
  36.     Next lngPos
  37.     Mid(strLastUsed, 8, 1) = Chr(intASC)
  38.     Me.txtTest = Right(strLastUsed, IIf(strLastUsed Like "0*", 7, 8))
  39.     lngLastPos = lngLastPos + 1
  40. End Sub
May 14 '17 #4

PhilOfWalton
Expert 100+
P: 1,430
Thanks a lot for that. Took a bit more fiddling, but working perfectly

Again my grateful thanks

Phil
May 15 '17 #5

jforbes
Expert 100+
P: 1,107
This may be something you are not comfortable with, but when it comes to something like this, especially with the more basic users, I have found it's better to provide the user a Button that displays a centered Dialog Box, and has the Default displayed and editable, and OK and Cancel Buttons. The user can edit the Default to their liking and hit the correct button. This will eliminate all the confusion and the user will really only enter in the same amount of characters. To make it even easier, you could position the cursor at the end of the Default TextBox, then all they have to do is backspace the unwanted numbers out.
May 15 '17 #6

PhilOfWalton
Expert 100+
P: 1,430
That was my first instinct, and normally I would agree with you, but in this instance, time is of the essence and as Neopa pointed out to me, using both the keyboard and a mouse slows the operation down.
So the latest version is keyboard only, and basically, after updating the record, the cursor moves to the the Combo box where I enter the next competitors's number.

But thanks for the obsevation

Phil
May 15 '17 #7

Post your reply

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