Results 1 to 3 of 3

Thread: Array + Input Parameter

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    31

    Array + Input Parameter

    Hi everyone,

    I have implemented a subroutine. Here is the signature :
    Code:
    Public Sub MySubroutine(ByRef arrMyArray() As Integer, ByRef lngMyLong As Long)
    I want to call my subroutine without passing in any variables.
    I passed in 0 as lngMyLong but I have had to create an array to pass in the subroutine as arrMyArray.

    Is there a way to call my subroutine without passing in an array variable ?

    Thanks in advance for your future help

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Array + Input Parameter

    Rather than passing fake values, just specify that they should be optional:
    Code:
    Public Sub MySubroutine(Optional ByRef arrMyArray() As Integer, Optional ByRef lngMyLong As Long)
    If you want to, you can even set a value that will be used if nothing is passed:
    Code:
    Public Sub MySubroutine(Optional ByRef arrMyArray() As Integer, Optional ByRef lngMyLong As Long = -1)

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Array + Input Parameter

    Arrays can't be optional parameters, but variants can be. Otherwise, agree with suggestion
    Code:
    Public Sub MySubroutine(Optional ByRef arrMyArray As Variant, Optional ByRef lngMyLong As Long)
        If IsMissing(arrMyArray) = False Then
            If VarType(arrMyArray) = (vbArray Or vbInteger) Then
                ' process your array
            End If
        End If
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Tags for this Thread

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