In VB List Box, Different Limits for List Property or AddItem

ID Number: Q80965

1.00

MS-DOS

buglist1.00

Summary:

One item in a list box can contain up to 1K of text when you use the

AddItem method. By assigning the text directly to the List property,

you can incorrectly assign more the 1K of text to a list box item. The

1K limitation was implemented with AddItem to overcome a Windows 3.0

problem related to list boxes. The 1K list box item text limitation

should also apply when assigning text directly to an item of a list

box.

Microsoft has confirmed this to be a problem with Microsoft Visual

Basic programming system version 1.0 for Windows. We are researching

this problem and will post new information here as it becomes

available.

More Information:

The following examples show the difference between using the AddItem

method and assigning the text directly to a list box item.

1. Run Visual Basic, or from the File menu, choose New Project (ALT,

F, N) if Visual Basic is already running. Form1 is created by

default.

2. Place two list box controls (List1 and List2) on Form1.

3. Double-click on Form1 to open the Code window, and add the

following code:

Sub Form_Click ()

List1.List(0) = String$(4096, "A") 'Direct assignment

a$ = List1.List(0)

Print Len(a$) 'Will print 4096

List2.AddItem String$(4096, "A") 'Using the AddItem method

a$ = List2.List(0)

Print Len(a$) 'Will print 1024

End Sub

4. From the Run menu, choose Start (ALT, R, S) to run the program.

While the program is running, click on Form1. The values 4096 and 1024

will be printed on the form. These values represent the result of

attempting to add 4K of text to a list box item. Assigning the text

directly to the first item (item 0) of List1 incorrectly allows 4K of

text to be assigned to the list box item. Using the AddItem method in

an attempt to assign 4K of text to the first item of List2 correctly

allows only 1K of text to be assigned to the list box.

Additional reference words: 1.00