开发者

VB6: what is likely cause of Overflow error when using strings?

In VB6, what is the likely开发者_开发百科 cause of an Overflow error? I am using strings when it occurs.

Is it RAM, or hard-drive space? Or is it something internal to VB6?


I am going to take a stab in the dark here, some code would help as Hogan said. Typically overflow error occur with string when VB6 things it is dealing with integer or longs in math formulas and the results are too large for a integer or long to hold.

Depending on the nature of your formula you may get away from the problem by forcing the system to use the numbers as floating point by adding a '.0" at the end. Otherwise use the various Cxxx function to explicitly convert the numbers to a type that has a greater range.

The one thing you consider is that floating point are less precise than whole number integers so make sure you don't lose needed precision when you do the conversion.


Another 'stab', since no code is provided ...

The following will produce an overflow error:

Dim x as integer
x = len(longstring)   'longstring over 32,768 characters in length

Would cause an overflow error.

Dim x as long
x = len(longstring)   'longstring over 32,768 characters in length

Works fine.

Another example of an overflow from Microsoft Support here:

EDIT

A more subtle situation that can catch you off guard:

You attempt to use a number in a calculation, and that number is coerced into an integer, but the result is larger than an integer.

Dim x As Long
x = 2000 * 365 ' Error: Overflow

To work around this situation, type the number, like this:

Dim x As Long
x = CLng(2000) * 365
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜