PDA

Click to See Complete Forum and Search --> : Oh yeah here's a real question . . .


Phobic
Nov 6th, 1999, 03:05 AM
When you want to create a procedure, like a Function, and you want to be able to call that function for as many objects as you want... example:


Sub MySub (Str1 as String, Optional Str2 as String, Optional Str3 as String)


How do I get the sub to have more than just two optional string variables?

Yonatan
Nov 6th, 1999, 04:21 AM
Try this:

Option Explicit

Sub MySub(ByVal NonOptionalString As String, ParamArray OptionalStrings() As Variant)
Dim Count As Long
Print "Non Optional String: " & NonOptionalString
For Count = 0 To UBound(OptionalStrings)
Print "Optional String " & Count + 1 & ": " & OptionalStrings(Count)
Next
End Sub

Private Sub Form_Load()
AutoRedraw = True
Call MySub("Sample", "ABC", "DEF", "GHI", "JKL")
End Sub

------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)