How to pass 30 arguments to a sub

Posted on 2011-03-03
Last Modified: 2012-05-11
I have a need to pass multiple arguments to a subroutine. But can't seem to get it to work.
I get "Wrong number of arguments or invalid property assignment"
Dim WToteCnt As Variant
  Dim WToteWt As Variant
  Dim WDrCnt As Variant
  Dim WDrWt As Variant
  Dim FDrCnt As Variant
  Dim FDrWt As Variant
  Dim CDrCnt As Variant
  Dim CDrWt As Variant
  Dim WFiveCnt As Variant       'Number of water fives
  Dim WFiveWt As Variant      'weight of water fives
  Dim FFiveCnt As Variant        'Number of flammable fives
  Dim FFiveWt As Variant        'weight of flammable fives
  Dim CFiveCnt As Variant       'Number of combustible fives
  Dim CFiveWt As Variant       'weight of combustible fives
  Dim CReducerOnesCnt As Variant
  Dim CReducerOnesWt As Variant
  Dim WOnesCnt As Variant        'Number of water ones
  Dim WOnesWt As Variant         'weight of water ones
  Dim FOnesCnt As Variant      'Number of flammable ones
  Dim FOnesWt As Variant       'weight of flammable ones
  Dim FRedOnesCnt As Variant     'Reducer ones   6/cs
  Dim FRedOnesWt As Variant      'Reducer weight
  Dim COnesCnt As Variant        'Number of combustible ones
  Dim COnesWt As Variant         'weight of combustible ones
  Dim FQrtCnt As Variant        'Number of flammable quarts
  Dim FQrtWt As Variant        'weight of flammable quarts
  Dim FPintCnt As Variant         'Number of flammable pints
  Dim FPintWt As Variant         'weight of flammable pints
  Dim WEaCnt As Variant
  Dim WEaWt As Variant
  Dim row As Integer             'Row count for DT
  Dim prow As Integer            'Rpw count for freight bill
  Dim Rname As Variant           'Reducer
  Dim Rlet As Variant            'First letter of flammable 1's(Currently we don't have
  Dim TotalWt As Variant                              ' anything that is not a reducer)Either 231,301
  Dim TotalDrCnt As Variant
  Dim CurSht As String

   Call CheckProd(FFiveCnt)

Open in new window

Question by:CRHIV
LVL 30

Expert Comment

ID: 35032222
If the sub supports 30 then do this

Call CheckProd(Arg1,Arg2,Arg3,Arg4,Arg5,......Arg30)


Author Comment

ID: 35032242
If they go to the sub, do they come back when the sub ends?
LVL 30

Expert Comment

ID: 35032255
I would like to see the sub before I answer that :)

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

LVL 23

Expert Comment

ID: 35033397
You could use an array, type or class.


A Type is made up of other basic variable types. You may be familiar with Types from other programming languages, in which they are called a struct, structure, or record. For example, we could declare a Type that describes an employee:

Type Employee
    Name As String
    Address As String
    Salary As Double
End Type

This defines a single type named Employee which has three elements: Name, Address, and Salary. You can then create variables of the Employee type and give values to the elements. For example,

Dim Manager As Employee
Manager.Name = "Joe Smith"
Manager.Address = "123 Main Street"
Manager.Salary = 40000

you can then pass the type (eg employee) by reference which is the default for subs and any changes made to the values in the type will be visible to the rest of the application.

LVL 11

Expert Comment

ID: 35035086
Whether variables can be changed in the called sub depends on your decalration in the arguments list. Variables listed with the ByVal keyword will not return changed, ByRef variables can be changed.
There is an exception: All Object variables are always passed ByRef, so can be modified in the called sub.
LVL 45

Accepted Solution

patrickab earned 50 total points
ID: 35039196

Make it simple. Pass an array of all the variables to the sub. That's faster and easier.


Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question