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

Procedure too long

Status
Not open for further replies.

craiogram

MIS
Feb 20, 2004
126
US
I'm using a form where in my Initialize sub I adding items to the various listboxes that are on the form but it appears that I've gone beyond the allowable space. Is there some way to call a function or a sub-routine and pass it the listbox object so that I can fill the list in there? Or some other way to get all my listboxes filled?

Thank you in advance...
 

If you show your code we may be able to help you....

Have fun.

---- Andy
 
My apologies,

I fill the list boxes with code like this:
ListBox1.AddItem ("value1")
ListBox1.AddItem ("value2")
.
.

ListBox2.AddItem ("value1")
ListBox2.AddItem ("value2")
.
.

and on and on for various listboxes all throughout the form.
All this code is leading to procedure too long.

can I do something like
call fillBoxes(listbox3)

so that in that sub I can continue to fill the listboxes
sub fillBoxes(listbox)
Listbox3.AddItem ("Value1")
Listbox3.AddItem ("Value1")
.
.
end sub
Thank you in advance.
 
Please disregard as I have figured out how to set up the sub routine.
 
Well, I actually have the same question, so is there any way you could post your solution? Thanks!
 
Look at Listbox.List, you can pass it an array of values.
 

It would be nice if craiogram would post the solution.

Here is one:
Code:
Call FillList1(ListBox1)
Call FillList2(ListBox2)
...

Private Sub FillList1(ByRef MyListBox1 as ListBox)

With MyListBox1
    .AddItems "Value1"
    .AddItems "Value2"
    ...
End With

End Sub

Private Sub FillList2(ByRef MyListBox2 as ListBox)

With MyListBox2
    .AddItems "ValueX"
    .AddItems "ValueY"
    ...
End With

End Sub

Have fun.

---- Andy
 
Why not simply bind the ListBoxes to some hidden Ranges ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or use arrays to fill them, as ettienne suggests, rather than endless .AddItem.

If the procedure is in the userform module, you do not need to use a ByRef.
Code:
Private Sub UserForm_Initialize()
    Call FillList1
End Sub


Sub FillList1()
   Dim MyList1()
   MyList1 = Array("Value_A", "Value_B", _
       "Value_C", "Value_D", _
       "Value_E", "Value_F")
   ListBox1.List = MyList1()
End Sub
In any case, on principle you should always break up long procedures into callable chunks. It makes debugging much easier.

faq219-2884

Gerry
My paintings and sculpture
 
My apologies, I didn't post any solution because I thought it was just a knuckle head oversight on my behalf.

It turns out that I didn't have to pass the listbox at all.

I simply made the call to the other sub from initialize sub like this:
Code:
Private Sub UserForm_Initialize()
Call filllist1thru5
Call fillList6thru10
End Sub

then just filled the listboxes as I did in the initialzie sub like this:
Code:
With ListBox1
    .AddItems "Value1"
    .AddItems "Value2"
    etc
End With
With ListBox2
    .AddItems "Value1"
    .AddItems "Value2"
    etc
End With

I thought I had to pass the listbox but you can access it from both subs the same way.

Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top