tags:

views:

36

answers:

1

I am using Visual Basic 6
I have the following code structure:
FUNCNINFO is a structure

Public funcTable() As FUNCNINFO
-----
------
ReDim Preserve funcTable(0 To upsize + ns)

When the value of (upsize + ns) is exceeding 32766,it is giving the runtime overflow error '6' Do you have any idea of the cause and the solution?

+3  A: 

VB6's Integer type is 16 bits so cannot store a value > 32767, its Long that's the 32 bit integer type so the following will work;

Dim upsize As Long
Dim ns As Long

upsize = 32766
ns = 12345

ReDim Preserve funcTable(0& To upsize + ns)
Alex K.
Hi Thanks..Please note that indvidual value of upsize and ns is not exceeding size of integer,it is there combination which is exceeding.
Pradeep
nor are they in my example, if they were both declared as integer (or not declared at all) then a error 6 overflow is thrown
Alex K.
Hi Rup,Yes this is array size limit in real scenario.
Pradeep
@Pradeep I think Alex is correct (+1 Alex). Please try changing your code to see whether it fixes the problem, and let us know what happens. If you don't want to change the type of your variables you could write `ReDim Preserve funcTable(0 To CLng(upsize) + CLng(ns))`
MarkJ
Thanks Alex and Mark.It works.
Pradeep