Parse Minutes Help!

Status
Not open for further replies.

twildt

New member
Joined
Jan 24, 2014
Messages
1
Programming Experience
Beginner
I'm having a small issue with my code in an access database. If you might get a moment to take a look for me or can direct me to whom I can forward this to I would be grateful!

I have a form field that operates under the following code. The code is supposed to parse the users input into the correct format to update its underlying table. The table holds minutes(15, 30, 240, etc.) but the form displays in h:nn format so the users can enter either 1:15 or 1.25 for their hours/minutes on a project.

My code isn't parsing properly. After you enter in your 1.5 or 1:30 the field blanks itself and comes back complaining you haven't entered data yet.

The code in question:

VB.NET:
'Parse Minutes
Public Function ParseMinutes(vTime As Variant) As Variant
Dim h As Long, m As Long, aTime As Variant
On Error GoTo ProcErr
 aTime = Split(vTime & "", ":")
 Select Case UBound(aTime)
   Case -1 ' no data entered - return null with no error
     ParseMinutes = Null
   Case 0 ' no colon found
     If Not IsNumeric(aTime(0)) Then Err.Raise 5 ' hours not numeric
     If aTime(0) < 0 Then Err.Raise 5 ' hours negative
     ParseMinutes = CLng(aTime(0) * 60)
   Case 1 'exactly one colon
     If Not IsNumeric(aTime(0)) Then Err.Raise 5 ' hours not numeric
     If aTime(0) <> CLng(aTime(0)) Then Err.Raise 5 ' hours not whole number
     If aTime(0) < 0 Then Err.Raise 5 ' hours negative
     If Not IsNumeric(aTime(1)) Then Err.Raise 5 ' minutes not numeric
     If aTime(1) <> CLng(aTime(1)) Then Err.Raise 5 ' minutes not whole number
     If aTime(1) < 0 Then Err.Raise 5 ' minutes negative
     If aTime(1) >= 60 Then Err.Raise 5 ' minutes 60 or more
     ParseMinutes = aTime(0) * 60 + aTime(1)
   Case Else ' more than one colon
     Err.Raise 5 ' invalid
 End Select
ProcEnd:
   On Error Resume Next
   Exit Function
ProcErr:
   ParseMinutes = Empty
   If Err = 5 Then
     MsgBox "Invalid time", vbExclamation
   Else
     MsgBox Err.Description, vbExclamation
   End If
   Resume ProcEnd
End Function
 
While this particular forum is dedicated to issues related to Access, this site is dedicated to VB.NET so I'm afraid VBA questions are off-topic. Sorry but I'll have to close this thread.
 
Status
Not open for further replies.
Back
Top