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

In Excel Userform code you can do this: ListBox1.List() = array 1

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
Using this technique, you can very quickly load a listbox with values from an array. Is there an equivalent method in VB? Iterating a list and using the .Add method takes too long (about 1-2 seconds) when the form loads because it is calculated. Thanks for any ideas and/or suggestions!

Have a great day!

j2consulting@yahoo.com
 
Sadly not. It's one of the features of the Office VBA controls that really ought to be in the VB 6 controls, but isn't.

However, the Office controls can be used in VB; simply add the Microsoft Forms 2.0 Object Library component to your project, and use the listbox from that.

Be aware, though, that Forms 2.0 is not redistributable, so target PCs will theoretically have to have Office installed on them. Having said this, there are at a couple of ways of legitimately getting the library onto non-Office PCs, e.g. downloading and installing the Microsoft ActiveX Control Pad available from here:
(actually, I'm going to post the direct download URL as well, as MS have a habit of archiving off old MSDN pages, which means the above link may soon vanish...
 
Thanks, I was kind of afraid that was going to be the answer. As a work-a-round, could you use the copy memory API to accomplish this task? I've played around with it a little bit and Hypetia has posted some code around here somewhere as well. If so, how would you determine the memory location for list(0)?

Thanks for any additional ideas and/or suggestions!

Have a great day!

j2consulting@yahoo.com
 
Well...probably...that's exactly one of the approaches I've investigated in the past (although without much luck).

However, you may be able to speed up populating the litbox by adopting two ideas:

1) use the LockWindowUpdate API call to lock the Listbox whilst all the additions are being done

2) Use SendMessage with LB_ADDSTRING (or even LB_INSERTSTRING) to load the listbox rather than the .AddItem method
 
Thanks, I just implemented loading the ListBox with SendMessage yesterday. I'll check out the LockWindowUpdate later today when I have a minute.

Thanks again for your responses. I hang out on Tek-Tips a lot and you frequently share excellent ideas. Which is what makes Tek-Tips by far my favorite technical forum.

Have a great day!

j2consulting@yahoo.com
 
Thanks again Strongm! I implemented LockWindowUpdate and it really helps to make things snap.

Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top