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

Dream Function: Loop Thru Value List 1

Status
Not open for further replies.

smandoli9

Programmer
Jun 10, 2002
103
US
I want to run a set of values through a procedure:

DoProcedure("strThing1")
DoProcedure("strThing2")
DoProcedure("strThing3")


I would love to do it with reiterating code:

For Each "strThing1", "strThing2", "strThing3"
DoProcedure()
Next


The way I usually attack this is to set up an array. Then I can use the index number of the array in a For...Each Loop.

For Each lngArrayIndex
DoProcedure(call on the array funct.)
Next


Is there a way to achieve the little fantasy construct in blue? I skip the declared array. I enter a value list, conceptually an array of course. The loop goes through the list.

Oh yeh, I have resorted to a table in the past. Prefer not.

-- SM
When will I be able to balance my net income with my gross habits?
 
This allows you to bury the loop overhead inside a procedure and gives you the syntax you want at the top level:

========================================================
Code:
Option Explicit
Sub test()
   DoAllProcedure "strThing1", "strThing2", "strThing3"
End Sub
Sub DoAllProcedure(ParamArray Parms() As Variant)
Dim i As Integer
For i = 0 To UBound(Parms)
  MsgBox "Calling DoProcedure with " + Parms(i) + " as parameter"
Next i
End Sub
=======================================================

Hope this helps.
 


Thanks! I think that is just what I was seeking.

(and, I finally have caught on that means I should hit the Star button.)

-- SM
When will I be able to balance my net income with my gross habits?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top