Proper order of elapsed time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using Doug Steele's Diff2Date function and I would like the elapsed time
to be sorted in proper order:
instead of :
1 second
12 seconds
2 seconds

1 second
2 seconds
12 seconds

Can someone tell me how this can be done?

Thank you.

Hopefully this will not double post, I submitted this earlier
 
Since what you're getting from the function is text, that IS "proper order",
but I understand what you're looking for... <g>

If you're strictly dealing with seconds, you could use the Val function on
what the function returns, and sort on it. That won't work, though, if
you're getting, say, minutes and second: you'll get

1 minute, 59 seconds
1 second
12 seconds
2 seconds

If you're strictly dealing with times (hhh:nn:ss), you could change what the
function returns so that it returns something like the format I just
indicated. You could change:

If booCalcHours And (lngDiffHours > 0 Or ShowZero) Then
If booCalcHours Then
varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
lngDiffHours & IIf(lngDiffHours <> 1, " hours", " hour")
End If
End If

If booCalcMinutes And (lngDiffMinutes > 0 Or ShowZero) Then
If booCalcMinutes Then
varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
lngDiffMinutes & IIf(lngDiffMinutes <> 1, " minutes", "
minute")
End If
End If

If booCalcSeconds And (lngDiffSeconds > 0 Or ShowZero) Then
If booCalcSeconds Then
varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
lngDiffSeconds & IIf(lngDiffSeconds <> 1, " seconds", "
second")
End If
End If

to

If booCalcHours And (lngDiffHours > 0 Or ShowZero) Then
If booCalcHours Then
varTemp = Format(lngDiffHours, "000")
End If
End If

If booCalcMinutes And (lngDiffMinutes > 0 Or ShowZero) Then
If booCalcMinutes Then
varTemp = varTemp & ":" & _
Format(lngDiffMinutes, "00")
End If
End If

If booCalcSeconds And (lngDiffSeconds > 0 Or ShowZero) Then
If booCalcSeconds Then
varTemp = varTemp & ":" & _
Format(lngDiffSeconds, "00)
End If
End If
 
I cannot imagine ever being able to remember all that, however I have been
able to figure outt how to cut and paste your change into the function.
Thank you Mr. Steele.

(Text should always be in proper order, and as you say, it is ">) )
--
Jeff C
Live Well .. Be Happy In All You Do


Douglas J. Steele said:
Since what you're getting from the function is text, that IS "proper order",
but I understand what you're looking for... <g>

If you're strictly dealing with seconds, you could use the Val function on
what the function returns, and sort on it. That won't work, though, if
you're getting, say, minutes and second: you'll get

1 minute, 59 seconds
1 second
12 seconds
2 seconds

If you're strictly dealing with times (hhh:nn:ss), you could change what the
function returns so that it returns something like the format I just
indicated. You could change:

If booCalcHours And (lngDiffHours > 0 Or ShowZero) Then
If booCalcHours Then
varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
lngDiffHours & IIf(lngDiffHours <> 1, " hours", " hour")
End If
End If

If booCalcMinutes And (lngDiffMinutes > 0 Or ShowZero) Then
If booCalcMinutes Then
varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
lngDiffMinutes & IIf(lngDiffMinutes <> 1, " minutes", "
minute")
End If
End If

If booCalcSeconds And (lngDiffSeconds > 0 Or ShowZero) Then
If booCalcSeconds Then
varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
lngDiffSeconds & IIf(lngDiffSeconds <> 1, " seconds", "
second")
End If
End If

to

If booCalcHours And (lngDiffHours > 0 Or ShowZero) Then
If booCalcHours Then
varTemp = Format(lngDiffHours, "000")
End If
End If

If booCalcMinutes And (lngDiffMinutes > 0 Or ShowZero) Then
If booCalcMinutes Then
varTemp = varTemp & ":" & _
Format(lngDiffMinutes, "00")
End If
End If

If booCalcSeconds And (lngDiffSeconds > 0 Or ShowZero) Then
If booCalcSeconds Then
varTemp = varTemp & ":" & _
Format(lngDiffSeconds, "00)
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top