Strong Typed Optional Array Parameter
Does anyone know how to create a strongly typed byref optional array to a sub/function in VB? I have sub I'm working on where the last three parameters are optional. The last two happen to be arrays (one should be boolean and the other string).
If I was to require the parameters, then I'd simply call it like so:
ByRef ColumnHeaders As String, ByRef VisibleCols() As Boolean, ByRef ColumnFormats() As String
But I want them to be optional.
But when I add Optional to the array parameters, I get a syntax error saying that they should be variant or some specific type with a default value.
Tg
Re: Strong Typed Optional Array Parameter
In VB6 optional argument must be eother Variant or of an intrisic data type. Also, by default all arguments are passed ByRef any way so you don't have to explicitly specify that.
Take a look at this very simple sample:
VB Code:
Option Explicit
Private Function Test(sColumnHeaders As String, _
Optional VisibleCols As Variant, _
Optional ColumnFormats As Variant) As String
'==================================================================
Test = "Not OK Yet"
If Not IsMissing(VisibleCols) Then
If VisibleCols(0) = True Then
Test = "OK"
End If
End If
End Function
Private Sub Command1_Click()
Dim arBool(1) As Boolean
arBool(0) = True
arBool(1) = True
MsgBox Test("abc", arBool)
End Sub