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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,223,099
Messages
6,170,108
Members
452,302
Latest member
TaMere

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