home bbs files messages ]

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,473 of 10,840   
   AmazingAccuracy.com to rickNOSPAMnews@NOSPAMcomcast.net   
   Re: Overflow? What gives?   
   24 Apr 07 18:38:10   
   
   From: noreply@cox.net   
      
   Thanks Rick.   
      
   After some thought, I thought that maybe this was the case, that VB was   
   'temporarily' storing the result in Weeks thus causing the overflow. So I   
   had changed it to Long type.   
      
   Thanks for the advice to do so for all my Ints in the future.   
      
   Regards,   
      
   Webbiz   
      
      
   "Rick Rothstein (MVP - VB)"  wrote in   
   message news:UJCdnXx-XOHb8rPbnZ2dnUVZ_vOlnZ2d@comcast.com...   
   >> 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