Results 1 to 6 of 6

Thread: Overflow error. Why?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    110

    Unhappy Overflow error. Why?

    For the code below, there is a form in which I take the values of start, end, and intervals (such as maintenance, training, or simplesmenet, interval).

    If a user enters at the start: 23h10min00s: vector "start"will store "23" in "start (0)", "10 " in "start (1)" and "0" in "start (0)" and so also for the other vectors.

    However, if a user type "20h15min10s" in the "beginning" and the "end" type "2h00min00s" (this is only possible if there another day), then the routine checks "end <start" and gives a Boolean value for the "midnight" and follow the code:

    Code:
    If midnight = False Then 'if there was no change of days, then proceeded by calculating normal
    Total_time_in_seconds = (3600 *end(0).Value + 60 * termino(1).Value + termino(2).Value) - (3600 * start(0).Value + 60 * inicio(1).Value + inicio(2).Value) - (3600 * interval(0).Value + 60 * interval(1).Value + interval(2).Value) - (3600 * maintenance(0).Value + 60 * maintenance(1).Value + maintenance(2).Value) - (3600 * training
    (0).Value + 60 * training(1).Value + training(2).Value)
    
    Else 'but if there was a change of days, then the total time in seconds is given by another formula:
    
    'tells how many seconds the machine work:
    FirstDay = 3600 * 24 - (3600 * beginning (0) + 60 * start (1) + start (2)) 'on first day
    SecondDay = (3600 * finish (0) + 60 * end (1) + end (2)) 'and the second day
    
        
    'sum over time, in seconds, the machine worked on the second day, and finally subtract the time of intervals
       Total_time_in_seconds = FirstDay + SecondDay - (3600 * interval(0).Value + 60 * interval(1).Value + interval(2).Value) - (3600 * maintenance(0).Value + 60 * maintenance(1).Value + maintenance(2).Value) - (3600 * training
    (0).Value + 60 * training(1).Value + training(2).Value)
    What's wrong?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Overflow error. Why?

    What data type are you using to declare your variables?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    110

    Re: Overflow error. Why?

    Nothing, just:

    "Dim training(3)" or "Dim FirstDay"

    I think I know where the error is. I separated these great phrases into smaller pieces:
    Code:
    DownTime = (3600 * interval(0) + 60 * interval(1) + interval(2)) + (3600 * maintenance(0) + 60 * maintenance(1) + maintenance(2)) + (3600 * training(0) + 60 * training(1) + training(2))
    
    If midnight = False Then 
    Total_time_in_seconds = (3600 *end(0) + 60 * end(1) + end(2)) - (3600 * start(0) + 60 * start(1) + start(2)) - DownTime
    
    Else
    
    FirstDay = (3600 *start(0) + 60 * start (1) + start (2)) 
    FirstDay = 3600 * 24 - FirstDay 'HERE IS THE ERROR: 3600*24. Why?
    SecondDay = (3600 * finish (0) + 60 * end (1) + end (2)) 
    
        
       Total_time_in_seconds = FirstDay + SecondDay -DownTime

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Overflow error. Why?

    You should ALWAYS specify a data type. Leaving the data type off of a declaration will cause the variable to become a Variant, and your overload could be because you are exceeding what a Variant can hold.

    Start with declaring them as longs and see if that fixes the problem.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    110

    Re: Overflow error. Why?

    I tried, but it's not working as well:

    Sub seconds_day()

    MsgBox 3600 * 24

    End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    110

    Re: Overflow error. Why?

    We need use CLng()

    Sub test()
    Dim x As Long
    x = CLng(3600) * 24
    MsgBox x
    End Sub

Tags for this Thread

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