title: Determine how many (optional) arguments where actually passed to VBA function?
body: <p>I'd like to define a function in Visual Basic which computes income tax in a given bracket. The inputs should be the income, the marginal tax rate, the lower bracket boundary, and - optionally - the upper bracket boundary. (For the top bracket there is no upper boundary).</p>
  
  <p>Here's how I went about it. First, I define a "ramp" function as follows:</p>
  
  <pre><code>Public Function ramp(x)
      ramp = (x + Abs(x)) / 2
  End Function
  </code></pre>
  
  <p>which is basically the same as IF(x&lt;0,0,x). Then I define the function (in Dutch) for the tax as</p>
  
  <pre><code>Public Function schijfbelasting(inkomen, ondergrens, bovengrens, tarief)
      schijfbelasting = ramp(tarief * (inkomen - ondergrens)) - ramp(tarief * (inkomen - bovengrens))
  End Function
  </code></pre>
  
  <p>Here "inkomen"=income, "ondergrens"=lower bracket boundary, "bovengrens"=upper bracket boundary, "tarief"=marginal tax rate, and the output "schijfbelasting"=tax in the specified bracket.</p>
  
  <p>This all works fine, except that I'd like to make the "bovengrens" (upper bracket boundary) optional using</p>
  
  <pre><code>Optional bovengrens
  </code></pre>
  
  <p>In Matlab, I would use the "nargin" (number of arguments) function to do something like the following:</p>
  
  <pre><code>Public Function schijfbelasting(inkomen, ondergrens, Optional bovengrens, tarief)
  If nargin==4
      schijfbelasting = ramp(tarief * (inkomen - ondergrens)) - ramp(tarief * (inkomen - bovengrens))
  Elseif nargin==3
  schijfbelasting = ramp(tarief*(inkomen-ondergrens))
  End If
  End Function
  </code></pre>
  
  <p>However, I'm not aware of a function similar to "nargin" in Visual Basic. It could also be something like "if the argument "bovengrens" is defined". Does anybody know how to approach this problem? Thanks in advance.</p>
  
  <p>P.S. I am aware that I can make the code 'work' by filling in a very large number for the bracket 'boundary' in the top bracket, but I do not consider this elegant coding.</p>