Pass large number of parameters

NMadson

New Member
Joined
Jul 11, 2012
Messages
7
I've written a VBA process that already passes 12 parameters to a Sub. In re-writing my code I find I want to pass another 12. There are four permutations of three variables. Since they are similar I thought there must be an easier way to pass these values. I looked at passing a two-dimensional array (variable name, variable value) but haven't worked with arrays that much and couldn't easily find a code example on the Web that would appear to solve my problem. Then I thought I could just write the values to a table in my database, since all my procedure is doing is updating some or all of the variables at each iteration of a loop.

Then I began to wonder if I shouldn't just type in the 12 parameters and be done with it.

Does anyone have any thoughts as to the efficiency and effectiveness of one solution over the other?

TIA,
Nolan
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I've written a VBA process that already passes 12 parameters to a Sub. In re-writing my code I find I want to pass another 12. There are four permutations of three variables. Since they are similar I thought there must be an easier way to pass these values. I looked at passing a two-dimensional array (variable name, variable value) but haven't worked with arrays that much and couldn't easily find a code example on the Web that would appear to solve my problem. Then I thought I could just write the values to a table in my database, since all my procedure is doing is updating some or all of the variables at each iteration of a loop.

Then I began to wonder if I shouldn't just type in the 12 parameters and be done with it.

Does anyone have any thoughts as to the efficiency and effectiveness of one solution over the other?

TIA,
Nolan

I'm sorry. After going back to my problem I realized there might be a better way to describe the array (if that's the way to go) I want. There would be two columns and twelve rows. The columns are "Variable Name" and "Variable Value". (The fact that Variable Name is itself the result of three three iterations of (Hi, Avg, Lo) of four factors isn't relevant.)

N.
 
Upvote 0
It's always awkward passing in a lot of variables but if it works you don't need to change it. That said - yes, you have at least a half dozen options:

  • Array
  • VBA Collection
  • Scripting Dictionary (aka associative array)
  • Custom Class or Custom Type
  • Store in a (temporary) Table
  • Store in hidden Form Controls
 
Upvote 0
It's always awkward passing in a lot of variables but if it works you don't need to change it. That said - yes, you have at least a half dozen options:

  • Array
  • VBA Collection
  • Scripting Dictionary (aka associative array)
  • Custom Class or Custom Type
  • Store in a (temporary) Table
  • Store in hidden Form Controls

Thanks xenou.

I went with an array since I was somewhat familiar with that approach. I'll have to study up on the rest.

Nolan
 
Upvote 0

Forum statistics

Threads
1,215,972
Messages
6,128,003
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top