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

using additem for a multi column ComboBox

Status
Not open for further replies.

nochoice

Programmer
Jun 17, 2003
72
0
0
CA
Hi, It's me again.

What I would like to do is use AddItem to add an item to a Multi Column ComboBox.

What I currently use is an array. The problem with the array is I have to specify a length:

Dim myarray(2, 10000)

I made it 10,000 to ensure I had enough room.
To fill the combobox, I use:

ml.OLEFormat.Object.Column() = myarray

Note: ml.OLEFormat.Object is the name of the combobox

So now I end up with a ComboBox 10,000 rows long regardless. Is there any way for me to populate the ComboBox using AddItem, or to populate using Column() but have it stop when it hits a blank record?

Thanks in advance,
NoChoice
 
Do you have to dim the array right away - could you just dim it without the size specified and then redim it with the appropriate size when you know how big it needs to be?
i.e.
Dim MyArray() As Integer ' Declare dynamic array.

'Do code here to figure out how many elements

Redim MyArray(x) ' Allocate x elements
 
OK I tried that, here is my code:

Dim myarray() As Integer

myarray(0, Count) = sh.OLEFormat.Object.Name
myarray(1, Count) = sh.OLEFormat.Object.Caption

ReDim myarray(2, Count)
ml.OLEFormat.Object.Column() = myarray

Note: This is not all of my code, there are for loops and if statements between Dim and ReDim, but I think they are unnecessary here

I get a run-time error '13' type mismatch with the red line of code.

Have I done everything correctly? Any suggestions.....

Thanks Again,
NoChoice
 
Hhhmmm, Looks like I'm a little slow today.

I fixed that problem, I had declared myarray as an Integer and I should have declared it as a string:

Dim myarray() As String

However, my problems are not over yet.

I now get subscript out of range on the same red line of code. This sounds like I've reached the end of the array. Should I define count, then ReDim the array, then write to the array? I'll give that a try, in the mean time, any sugestions would be appreciated.

Thanks,
NoChoice
 
Thanks for your help ljallem.

Here's what I did:

1) Looped through and defined count - I did not fill my array at this point

2) ReDim Array as (2,count)

3) looped again and filled myarray

4) Populated the combo box.

I know this is a little sloppy and slow, but I couldn't think of any other way to do it.

Thanks,
NoChoice
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top