Results 1 to 2 of 2

Thread: Strong Typed Optional Array Parameter

  1. #1

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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:
    1. Option Explicit
    2.  
    3. Private Function Test(sColumnHeaders As String, _
    4.                       Optional VisibleCols As Variant, _
    5.                       Optional ColumnFormats As Variant) As String
    6. '==================================================================
    7.  
    8.     Test = "Not OK Yet"
    9.     If Not IsMissing(VisibleCols) Then
    10.         If VisibleCols(0) = True Then
    11.             Test = "OK"
    12.         End If
    13.     End If
    14.  
    15. End Function
    16.  
    17. Private Sub Command1_Click()
    18. Dim arBool(1) As Boolean
    19.  
    20.     arBool(0) = True
    21.     arBool(1) = True
    22.     MsgBox Test("abc", arBool)
    23.  
    24. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width