Hi again Jack.
This seems a lot better so thank you for your renewed efforts. It does indicate a certain lack of understanding in some places but then hopefully we can help with that. After all you wouldn't come for help if you needed none ;-)
Let me first refer back to one of the comments from my earlier post where I explained that a value, and the formatted string of that value, are entirely separate entities and should never be confused. As a general rule calculations should be done using the value itself and only ever format results for viewing at the point where they need to be viewed. This will truly simplify your life.
Another very quick tip I'll share before proceeding as it can also help with all your work :
Avoid giving names to things (Anything - anywhere.) that are all in lower case. Intellisense will reflect the case you use so normally, if you see anything in all lower case, it means it's wrong. Intellisense hasn't recognised it or it wasn't Copy/Pasted from an actual project but someone's typed it out either from scratch or from a Word Processor. If you ever use names with all lower case though, you miss out on this extremely helpful benefit - thus giving yourself ongoing problems.
I see that the Function you posted is called
toseconds()
and it seems clear that you're taking an input of a formatted string instead of the actual value that should be available. This can work but you're making extra trouble for yourself. Seconds from a time value is much easier (& more reliable) as :
- Public Function ToSeconds(sDate As Date) As Long
-
ToSeconds = CLng(sDate * 86400&)
-
End Function
To convert back is equally simple :
- Public Function ToTime(lngSeconds As Long) As Date
-
ToTime = CDate(lngSeconds / 86400#)
-
End Function
Formatting such a returned value as HH:mm (Hours:Minutes) is as simple as :
- Format(ToTime(lngValue),"HH:nn")
Now, it seems I'm still a little in the dark as to what your problem is but I have a suspicion that your troubles are related to trying to sum string values. That simply isn't going to work. If you take away the understanding that you need to work with the values as they come to you, and only ever format them when it comes to the point of showing the results, then I suspect all problems will melt away as mist.
If not, share again the point to which you have reached, including a clear description of what fails (including any error messages if there are any of course) and we will try to help from that point.
PS. Though I always try to format my code suggestions as you'd expect if Copy/Pasted I have to admit to typing it out from scratch in most cases. I do focus on ensuring I don't introduce errors that way but honesty impels me to admit I break my own rules. In my defence I'm quite experienced and quite successful at avoiding errors.