Results 1 to 17 of 17

Thread: Calculating time??

  1. #1

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Thx for the code mendhak! But this will still give me 8,12. Another try???

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    OK, explain how you got the 2 there.

    I got the '8' part, but the '2' part wasn't so clear.

  3. #3

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    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??

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Well, didn't you just answer your own question.

    VB Code:
    1. Dim abc As Integer
    2. abc = (DateDiff("n", "08:00", "16:12"))
    3. Dim def As Integer
    4. def = abc / 60
    5.  
    6. Dim ghi As Single
    7. ghi = abc Mod 60
    8.  
    9.  
    10.  
    11. MsgBox (def & "," & ghi / 6)

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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?

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    VB Code:
    1. Dim abc As Single, begin As Integer, temp As String
    2.  
    3.  
    4. abc = (DateDiff("n", "08:00", "16:58")) / 60
    5.  
    6.  
    7.  
    8. mytime = Format(abc, "#.#")
    9.  
    10. begin = InStr(CStr(abc), ".")
    11.  
    12. temp = Mid(CStr(abc), 1, begin + 1)
    13.  
    14. mytime = CSng(temp)
    15. MsgBox mytime

  7. #7

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Have you tested your code?

    mytime = 8

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I got 8.9

    what have you changed? Post ur code again.

  9. #9

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    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.....

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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

  11. #11

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Im not in a rush. Take your time...

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Ok, I'm still getting 8.9.

    Did you try again? Maybe you have VB Weirdo version or something

    Maybe you should take my code and start again.

  13. #13

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Yepp! Still got 8. Can it be something that is different beacuse of my languagesettings? (Swedish)

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by Libero
    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?

    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.

  15. #15

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Originally posted by mendhak


    Maybe you're implying that the Swedes don't know how to perform simple mathematical operations?
    Maybe the swedes can see the fact and let other people do the mathematical operations.

    I will step trough the code later today and se whats wrong. Thx for your assistance..

  16. #16

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Yippiiiieeee!! Got it now!

    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


  17. #17
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width