Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overflow error with variant data types

Status
Not open for further replies.

Motor11

Technical User
Jul 30, 2002
60
US
Hello gentlemen,

When running a program, I get an overflow error. If I put a breakpoint on the offending line, the overflow errors cease.

The code is:
x_small = CDec(xavg - (scale_val / 1.9))

All the variables are variants (scale_val is a decimal) and have been declared as such.

When the prgram crashes, the debugger shows the following values:
xavg=-89.07735319
scale_val=2.16080000001284E-04

I have also tried x_small and xavg as doubles with the same error. Scale_val becomes zero if I make it a double, so I've used the cdec function to make it a decimal/variant.

Strangely, this error only occurs the second time through the snippet of code. The first time through (with the exact same values for all variables) it runs fine, if, however, I invoke this subroutine again, the overflow occurs.

I am using VB 5 for this project.

Thanks in advance,
Ryan
 
I see nothing in the snippet of code that would suggest an overflow would occur. But it is hard to tell if the error is because of external value assignments to these variables or a some other side effect. Is the subroutine modifying public variables or is it used in a function with a defined return data type?





Mark
 
Is there an outside influence at work? Is the function return value declared as Double or what?

I can't duplicate your results in VB6 (haven't got VB5 any more).
In VB6 with your figures it all gives same results with or without CDec as long as evrythings declared as Double Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
I have managed to uncover more information about this problem.

I was using the result of the calculation to set the bounds of a picturebox.

see below:
Mainform.scatter.Scale (x_small, y_large)-(x_large, y_small)

if I remark that line, the overflow error on this line goes away:
x_small = CDec(xavg - (scale_val / 1.9))

So, apparently, my value wasn't outside the bounds of the variant data type, but was outside the allowable value for setting the boundaries of a picture box. Does this sound
plausible?

Thanks for the replies,
Ryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top