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,468 of 10,840    |
|    Rick Rothstein (MVP - VB) to All    |
|    Re: Overflow? What gives?    |
|    24 Apr 07 16:57:41    |
      From: rickNOSPAMnews@NOSPAMcomcast.net              > Dim Weeks As Integer       >       > '***** 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              Because Weeks is declared as an Integer and 7 can fit into an Integer, VB       stores the intermediate calculation in as Integer, or at least it tries       to... 40117 is too big to fit in an Integer, so you get an overflow error.       There is almost no reason to declare variables as Integer (Longs are faster       in a 32-bit world), so I would simply declare Weeks as Long, which should       take care of your problem (as long as one of the values is bigger than an       Integer, VB will not perform the intermediate calculations as Integer, even       if the other value is an Integer). If you need Weeks to be an Integer for       other reasons, then simply change 7 to 7& (which make 7 a Long value); or       change the 7 to CLng(7) which has the same effect.              Rick              --- 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