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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox listcount returning negative

Status
Not open for further replies.

crystalhelp

Programmer
May 13, 2002
56
CA
I have a listbox which I populate with a resultset. My resultset brings back 428,700 rows. But when I ask for the listcount it gives me -30052. Why? The listcount works when the resultset is smaller. Is there a maximum size a listbox can handle? Thanks.
 
Standard MS Listboxes are limited to 32K ( 32768 ) individual items( essentially, the same as an integer variable ), and each item is limited to 1K in size.

Robert
 

Could be wrong but I thought most controls had a limit of the type that refers to individual values, i.e. to refer to an item in a listbox it would be...

[tt]
List1.List(Integer) As String
[/tt]

and an integer in vb has a max values of -32,768 to 32,767

And try as I might I cannot find that error listed in MSDN. I remember being able to look up specific error codes and return values but for the life of me I cannot find that (-30052) error code.

I think I know why now I just tried this code
[tt]
Private Sub Form_Load()
Dim I As Double

For I = 0 To 40000
List1.AddItem I
DoEvents
Next I

MsgBox List1.ListCount

End Sub
[/tt]
and recieve a listcount of -25535
 
The VB listboxes are quite happy handling more items than this - as long as you use API calls to populate and interrogate them.
 
A 16-bit field can either store a straight (non-signed) 16 bit integer (0 to 65535) or a signed integer ( that's 1 sign bit plus a 15 bit number (0 to 32767)).

Most VB stuff uses signed numbers, so if you overrun from 32767, the number will be displayed as a negative value.

Negative numbers are stored as 1's complements. This means that -1 returns &HFFFF, and why vb5prgrmr gets -25535 as his listcount.

&HFFFF is 65535, add the 1 to get 65536 (2^16)
40001 (actual listcount) add 25535(as displayed) gives 65536 also 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.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top