Thx for the code mendhak! But this will still give me 8,12. Another try???
Printable View
Thx for the code mendhak! But this will still give me 8,12. Another try???
OK, explain how you got the 2 there.
I got the '8' part, but the '2' part wasn't so clear.
1 Hour = 60 minutes, i got to split his 60 minutes up into 10 periods. Then each period will be 6 minutes.
12 minutes is then the same as 2 periods (12/6=2)
Got it?? :confused:
Well, didn't you just answer your own question. :p
VB Code:
Dim abc As Integer abc = (DateDiff("n", "08:00", "16:12")) Dim def As Integer def = abc / 60 Dim ghi As Single ghi = abc Mod 60 MsgBox (def & "," & ghi / 6)
First of all use dim abc as single. A simple dim abc is bad coding.
when you apply format() it too rounds up you function.
now, your division yields 8.99996
The only way I can think of right now is to convert that to string, extract upto the first char after the decimal, and reconvert back to single.
Is that OK with u?
VB Code:
Dim abc As Single, begin As Integer, temp As String abc = (DateDiff("n", "08:00", "16:58")) / 60 mytime = Format(abc, "#.#") begin = InStr(CStr(abc), ".") temp = Mid(CStr(abc), 1, begin + 1) mytime = CSng(temp) MsgBox mytime
Have you tested your code?
mytime = 8 :confused:
I got 8.9
what have you changed? Post ur code again.
Here we go:
Dim abc As Single, begin As Integer, temp As String
abc = (DateDiff("n", "08:00", "16:58")) / 60
mytime = Format(abc, "#.#")
begin = InStr(CStr(abc), ".")
temp = Mid(CStr(abc), 1, begin + 1)
mytime = CSng(temp)
MsgBox mytime
I am so glad that u will help.....:)
Dude, I got 8.9 with ur code.
Try again.
I'm going home right now (Mongolia time: 6:30 pm) I'll be at home later, I can check it out then if u aren't in a rush. else grab someone else here.
cya
Im not in a rush. Take your time...:o
Ok, I'm still getting 8.9.
Did you try again? Maybe you have VB Weirdo version or something :rolleyes:
Maybe you should take my code and start again.
Yepp! Still got 8. Can it be something that is different beacuse of my languagesettings? (Swedish)
Maybe you're implying that the Swedes don't know how to perform simple mathematical operations? :DQuote:
Originally posted by Libero
Yepp! Still got 8. Can it be something that is different beacuse of my languagesettings? (Swedish)
OK, I think you should step through your code then.
Place a breakpoint next to each and every line and check all the values you're getting. I seriously doubt it would be a problem with your language settings or even your processor for that matter.
Maybe the swedes can see the fact and let other people do the mathematical operations.:pQuote:
Originally posted by mendhak
Maybe you're implying that the Swedes don't know how to perform simple mathematical operations? :D
I will step trough the code later today and se whats wrong. Thx for your assistance..:)
Yippiiiieeee!! Got it now!:D
Your code:
Dim abc As Single, begin As Integer, temp As String
abc = (DateDiff("n", "08:00", "16:58")) / 60
mytime = Format(abc, "#.#")
begin = InStr(CStr(abc), ",") ' separator was "." changed it to a comma
temp = Mid(CStr(abc), 1, begin + 1)
mytime = CSng(temp)
MsgBox mytime
:D :D :D
Great.