Solved

Overflow when loading list box from array

Posted on 2003-10-28
8
222 Views
Last Modified: 2010-05-01
I am getting an overflow message when loading a list box with 32000 records can someone help please.
   For i = 0 To arrsize
         combinedarray(i) = frmsort.List2.List(i)
    Next

Thanks
0
Comment
Question by:running32
8 Comments
 
LVL 10

Expert Comment

by:MrClyfar
ID: 9635120

Hi there.

Try

 For i = 0 To arrsize - 1
         combinedarray(i) = frmsort.List2.List(i)
Next

As you are using zero-based arrays, the start index being 0, you must use the '- 1' at the end of the For i = 0 line.

Hop this helps.
Jas.
0
 
LVL 9

Expert Comment

by:dancebert
ID: 9635151
Your code sample does not match the problem description
>  combinedarray(i) = frmsort.List2.List(i)

This code doesn't load a listbox, it assigns a value to an array.

0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9635208
Have you tried:

   For i = 0 To arrsize
        ReDim Preserve combinedarray(i)
        combinedarray(i) = frmsort.List2.List(i)
    Next
0
 

Author Comment

by:running32
ID: 9635495
dancebert is correct I had loaded my list box with the values I am writing them out to an array.  So that would mean my array is not big enough?

below is my  code to make the array the same size at the list box

   i = i - 1
   x = i
   Dim arrsize As Long
   arrsize = i
   Do
     
 
       frmsort.List2.AddItem (combinedarray(i))
       If i = "10" Then
         MsgBox ("here")
       End If
      i = i - 1
      Loop While (i <> 0)
     Dim probelistvariable
     ' write to array from list

    ReDim combinedarray(frmsort.List2.ListCount )
    For i = 0 To arrsize
         combinedarray(i) = frmsort.List2.List(frmsort.List2.ListCount)
    Next
     
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:dancebert
ID: 9635640
I don't see where you original dim combinedarray.  What data type are you using?  If you did

dim combinedarray() as integer

You'd get an overflow error if you attempted to assign a value that was larger than the largest integer.
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 500 total points
ID: 9635667
How about:

Dim i As Integer, combinedarray() As String

For i = 0 To frmsort.List2.ListCount - 1
    ReDim Preserve combinedarray(i)
    combinedarray(i) = frmsort.List2.List(i)
Next i
0
 
LVL 8

Expert Comment

by:fozylet
ID: 9636093
Is the record count exactly 32k or is it going over integer limit, hence making i to overflow.
0
 
LVL 9

Expert Comment

by:dancebert
ID: 9636353
What was combinedarray dim'd as before you changed it to string?
What datatypes are you storing in the array?

If you're storing numbers into a string that will cure your overflow error.  So would have my solution, which was offered first.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Saving history changes to sub form 4 35
VBA filters 2 50
Visual Studio search word table and return Cell index 8 48
How to make an ADE file by code? 11 79
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now