>> >>-----Original Message----- >> >From: piclist-bounces@mit.edu On Behalf >> Of Dennis Crawley >> >Sent: Sunday, March 27, 2005 6:05 PM >> > >> >Hi, >> >I don't understand why VB rises an overflow error >> >when this is performed >> > >> >DELFN = 84 / (256 * (256 * (256 * (3 + beta) + 2) + 2) + 2) >> > >> >but nothing happens if is written like this >> > >> >DELFN = 84 / (256 * (Val(256) * (256 * (3 + beta) + 2) + 2) + 2) >> > ^^^ >> >VB mysteries? > > >Is the variable beta defined as an integer? If yes then: > >In most, if not all, Basic dialects the variable beta will be used to hold >the intermediate results during calculation. (256 * (3 + beta) + 2) fits >into an integer but the next * 256 overflows an integer sized variable. > >I believe the Val(256) function call is returning a variant that is used for >the remaining intermediate calculations avoiding the overflow condition. >While this works I don't think VB guarantees this method to work so, I >recommend you define beta as a long instead of an integer. Alternatively you >can copy beta to a long and use the long in the calculation. > >Paul Hutch I think that you can also define the value 256 as a long by appending the '&' character. Try DELFN = 84& / (256& * (256& * (256& * (3 + beta) + 2) + 2) + 2) This will force VB to use a LONG type to store the results. I am not expert on this but I think you will find it works. BTW. There certainly are better forums for getting info on VB problems than the piclist. You may get a dozen or so better answers on one of these boards. Regards, Jim Robertson NEWFOUND ELECTRONICS -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist