Entering Times

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    Entering Times

    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:-
    Code:
    Number Entered     Display
                       01:23:40
           5           01:23:45
           2           01:23:52
           1           01:25:21

    Any ideas please?

    Phil
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Just to be clear:
    You have an unbound textbox that you're entering the new time in?

    Comment

    • PhilOfWalton
      Recognized Expert Top Contributor
      • Mar 2016
      • 1430

      #3
      Yes the unbound textbox is InputElapsed1

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

      Code:
      Sub PartialTime()
      
          'Highlight and attempt to predict time of next finisher
          Dim StartTime As Date
          
          StartTime = Nz(DLookup("StartTime", "TblJoinRaceYear", "RaceID = " & RaceID & " AND YearID = " & DMax("YearID", "TblJoinRaceYear")))
          
          FinishTime.SetFocus
                  
          If IsNull(FinishTime) Then
              FTime = Nz(DMax("FinishTime", "QGroupFinishTime", "RaceGroupID = " & CboRaceGroupID))
              If FTime = 0 Then                           ' No finishers for this race so use start time
                  FTime = Nz(DLookup("StartTime", "TblJoinRaceYear", "RaceID = " & RaceID & " AND YearID = " & DMax("YearID", "TblJoinRaceYear")))
                  FinishTime = FTime
                  FinishTime.SetFocus
                  FinishTime.SelStart = 0
                  FinishTime.SelLength = 8
              Else
                  FinishTime = FTime
                  FinishTime.SetFocus
                  FinishTime.SelStart = 6
                  FinishTime.SelLength = 2
              End If
              If Second(FTime) > 57 Then                ' Probably next minute
                  FinishTime.SelStart = 3
                  FinishTime.SelLength = 5
              End If
          End If
          
          InPutElapsed = CStr(CDate(DateDiff("s", StartTime, FinishTime) / 86400))
          InputElapsed1 = InPutElapsed
      
      End Sub
      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

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Hi Phil.

        More details to follow later but the form has a TextBox called [txtTest] and the code below does what you need :
        Code:
        Option Compare Database
        Option Explicit
        
        Private strLastUsed As String
        Private lngLastPos As Long
        
        Private Sub Form_Open(Cancel As Integer)
            strLastUsed = "00:00:00"
        End Sub
        
        Private Sub txtTest_Enter()
            Me.txtTest = Right(strLastUsed, IIf(strLastUsed Like "0*", 7, 8))
            lngLastPos = 0
        End Sub
        
        Private Sub txtTest_KeyDown(KeyCode As Integer, Shift As Integer)
            If Shift <> 0 Then Exit Sub
            Select Case KeyCode
            Case vbKey0 To vbKey9
                Call ProcessKey(Asc("0") + KeyCode - vbKey0)
                KeyCode = 0
            Case vbKeyNumpad0 To vbKeyNumpad9
                Call ProcessKey(Asc("0") + KeyCode - vbKeyNumpad0)
                KeyCode = 0
            End Select
        End Sub
        
        Private Sub ProcessKey(intASC As Integer)
            Const conPos As String = "8775544221"
            Dim lngPos As Long, lngFrom As Long, lngTo As Long
        
            For lngPos = lngLastPos To 1 Step -1
                lngFrom = CLng(Mid(conPos, lngPos * 2 - 1, 1))
                lngTo = CLng(Mid(conPos, lngPos * 2, 1))
                Mid(strLastUsed, lngTo, 1) = Mid(strLastUsed, lngFrom, 1)
            Next lngPos
            Mid(strLastUsed, 8, 1) = Chr(intASC)
            Me.txtTest = Right(strLastUsed, IIf(strLastUsed Like "0*", 7, 8))
            lngLastPos = lngLastPos + 1
        End Sub
        Last edited by NeoPa; May 14 '17, 09:15 PM.

        Comment

        • PhilOfWalton
          Recognized Expert Top Contributor
          • Mar 2016
          • 1430

          #5
          Thanks a lot for that. Took a bit more fiddling, but working perfectly

          Again my grateful thanks

          Phil

          Comment

          • jforbes
            Recognized Expert Top Contributor
            • Aug 2014
            • 1107

            #6
            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.

            Comment

            • PhilOfWalton
              Recognized Expert Top Contributor
              • Mar 2016
              • 1430

              #7
              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

              Comment

              Working...