getminuteformat debug issue

CanadianAccessUser

Registered User.
Local time
Today, 18:53
Joined
Feb 7, 2014
Messages
114
I'm getting an error and I'm not sure why...
My code is meant to convert seconds into hh:mm:ss format.
I've attached screen shots.
 

Attachments

  • Error.jpg
    Error.jpg
    83.5 KB · Views: 74
  • Debug.jpg
    Debug.jpg
    89.2 KB · Views: 70
My guess is because in_Seconds is null. In that highlighted line of code you are not testing to see if in_Seconds is null, you are testing to see if the value you are calculating is null, which means that division gets done no matter what. My guess is if in_Seconds is null then this throws the error:

in_Seconds/3600

You need to test in_Seconds directly for null, not the calculation. If you properly structure you're code you should only do it once:

Code:
if (isnull(in_Seconds)= false))

    ' do all calculations here because in_Seconds has data

End If
 
What does it mean when I hover over and it says "hrs = empty"?
 
I think that's the error.
 
oh... ok I think I fixed that. I separated the Dim hrs, min, secs As Integer (shown below) and it now says that hrs = 0 when I hover

new question:
Why would it say "hrs = Int(in_Seconds / 3600) = <Automation Error>"
when I hover over hrs = Int(in_Seconds / 3600)?

Current code is:
Function getMinuteFormat(in_Seconds) As String
' converts numeric seconds (in_Seconds) into a string that displays hours, minutes and seconds (i.e. 340 = "5:40:25")
Dim ret As String ' variable to hold value to be returned, by default
Dim hrs As Integer
Dim mins As Integer
Dim secs As Integer ' variables to hold hours, minutes and seconds
ret = "00:00" ' default value to return
If (IsNull(in_Seconds) = False) Then
hrs = Int(in_Seconds / 3600)
mins = IIf((in_Seconds Mod 60) = 0, (in_Seconds / 60) Mod 60, Fix(in_Seconds / 60) Mod 60)
secs = in_Seconds Mod 60
End If
' determines how many whole hours and whole minutes are in in_Seconds, and how many remaining seconds
ret = hrs & ":" & Format(mins, "00") & ":" & Format(secs, "00")

getMinuteFormat = ret
End Function
 
Last edited:
I don't know. I do know that this line:

ret = hrs & ":" & Format(mins, "00") & ":" & Format(secs, "00")

needs to be inside the IF/End If

Try that and see if it works.
 
Firstly I would not accept a Variant as the parameter. That not only permits Nulls but alphas which will break the function completely. A function should only accept what it can handle. Passing other types to it is an error at the call and should be caught there.

Trap the Nulls in the call with Nz().

Use the Integer Division operator to return the integer part of the division.

Code:
Function getMinuteFormat(ByVal in_Seconds As Long) As String
 
    getMinuteFormat = in_Seconds \ 3600 & ":" _
                    & Format((in_Seconds Mod 3600) \ 60, "00") & ":" _
                    & Format(in_Seconds Mod 60, "00")
 
End Function
 

Users who are viewing this thread

Back
Top Bottom