|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Overflow strange behavior-UrgentHello,
It looks as suddenly, large numbers (not huge ones!) returned by function calls in vb6/vba create an overflow msg For exemple: Private Sub yyy() Call test(45) End Sub Function test(g) MsgBox 12336 * 4569 End Function What am I doing wrong? Please help Avi
Show quote
Hide quote
"avi" <avi***@bezeqint.net.il> wrote in message Not declaring your variables and functions as explicit types for one. The news:760b075c-e727-4839-9ec0-c68f34e90768@g19g2000yql.googlegroups.com... > Hello, > > It looks as suddenly, large numbers (not huge ones!) returned by > function calls in vb6/vba create an overflow msg > > For exemple: > > Private Sub yyy() > Call test(45) > End Sub > Function test(g) > MsgBox 12336 * 4569 > End Function > > What am I doing wrong? main problem though is that you are multiplying 2 Integer values together and getting a result that is too large for an Integer data type. Private sub yyy() call test(45) end sub Private function test(byval G as long) as long Msgbox 12336& * 4569 End function Since one of the values is now a Long (the trailing & indicator) the math will be performed using Long values and the overflow disappears. You can "promote" one or the other or both values or use the CLng function instead of the type suffix but the key is that at least one operand must be a type large enough for the result. avi <avi***@bezeqint.net.il>'s wild thoughts were released
on Mon, 6 Jul 2009 08:43:35 -0700 (PDT) bearing the following fruit: Show quoteHide quote >Hello, Using integers, both number can be stored as integers and> >It looks as suddenly, large numbers (not huge ones!) returned by >function calls in vb6/vba create an overflow msg > >For exemple: > >Private Sub yyy() > Call test(45) >End Sub >Function test(g) > MsgBox 12336 * 4569 >End Function > >What am I doing wrong? are, and the result is an integer. Hence the overflow Try MsgBox 12336& * 4569& This & declares the numbers to be long values and hence the return value will also be long. -- Jan Hyde
VB Express and VB files
Is my VB6 app form open? Vista 64 and Visual Studio 6 Keeping 2 listboxes in sync - VB6 ListBox - Limit Selection Rectangle Width In-Process and Out-of-Process Best method to have 2 checkboxes for 1 item Command Line Exporting a function from VB.net DLL Re: Problem using PictureBox_Resize event instead of subclassing |
|||||||||||||||||||||||