Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.visual.basic    |    MS Visual Basic discussions, NOT dot-net    |    10,840 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 10,470 of 10,840    |
|    AmazingAccuracy.com to All    |
|    Overflow? What gives?    |
|    24 Apr 07 15:33:17    |
      From: noreply@cox.net              I'm puzzled.              The following code is designed to take a date and a weekday count value, and       return the future date.              For example, if I supply it a starting date of 4/25/2007 and a count of 37,       it should return a date that is 37 weekdays only from 4/25/2007. It should       not count any weekends, only Monday-Friday days.              When I ran this code, it came back with an OVERFLOW error. Huh?              Function ForwardDate(ByVal EndDate As Date, _        ByVal DaysForward As Double) As Date              Dim RoundedDays As Long       Dim x As Long       Dim CalendarDays As Long       Dim Weeks As Integer       Dim Remainder As Single       Dim TimeDay As Date                             RoundedDays = CInt(DaysForward)               Weeks = Fix(RoundedDays / 5) 'trading day weeks               Remainder = RoundedDays Mod 5 'days left over               '***** THIS IS THE LINE THAT GIVES THE ERROR *****        'when Weeks = 5731. That comes out to 40117 which should be within        'the LONG range of CalendarDays.               CalendarDays = Weeks * 7 'convert trading day weeks to calendar days               TimeDay = EndDate + CalendarDays 'expand out by calendardays. should       fall on same weekday               'Now add the remainder days excluding weekends        For x = 1 To Remainder        TimeDay = TimeDay + 1        If Weekday(TimeDay) = vbSaturday Then: TimeDay = TimeDay + 2 'shift       from Saturday to Monday        Next x                      ForwardDate = TimeDay              End Function                            ======================              Program stops with an Overflow error on the line CalendarDays = Weeks * 7.       Looking at Weeks, it was equalling 5731. That is within range for an INT.       And when multiplied by 7, that should be within range of a LONG.              Can anyone see what I did wrong here?              Thanks.              Webbiz              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca