Pages

Friday, May 27, 2011

Create methods that accept an arbitrary number of parameters in ASP (VBScript 4.0)

VBScript doesn't support the ParamArray keyword in the declaration line of a method. So, if you'd like to create a subroutine or function that accepts an arbitrary number of parameters at runtime, have it accept a single parameter that's a variant array and use the Array method to call it.

Consider the following code:

printdata Array("She"," sells", " seashells")
printdata Array(" by", " the")
printdata Array(" seashore.")

Sub printdata(objArray)
  Dim val
  For each val in objArray
    response.write val
  Next
End Sub

This code prints the sentence: She sells seashells by the seashore. While the example isn't very useful, this technique is ideal if you have a function that allows you to customize a form. You could then call the function with only the parameters you want to
customize. The call might look something like this:

createForm array("Height:34","Width:22")


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.