Share via


How to: Pass an Array to a Procedure or Property (Visual Basic)

You pass an array the same way you pass any other variable. You supply the array variable name in the appropriate argument when you call the procedure or access the property.

To pass an array to a procedure

  1. Ensure that one of the procedure parameters specifies an array with the same rank (number of dimensions) and element data type.

  2. Supply the array variable at the corresponding place in the argument list. Do not follow the array name with parentheses.

    Public Function findLargest(ByVal numbers() As Double) As Double
        ' Insert code to calculate and return largest number.
    End Function
    Dim testNumbers() As Double = New Double() {5.0, 3.7, 1.2, 7.6}
    Dim largestNumber As Double = findLargest(testNumbers)
    

To pass an array to a property

  1. Ensure that one of the property parameters specifies an array with the same rank (number of dimensions) and element data type.

  2. Supply the array variable at the corresponding place in the argument list. Do not follow the array name with parentheses.

    Public Property bestMatch(ByVal formattedStrings() As String) As Double
        ' Insert Get and Set procedures for number best matching strings.
    End Property
    Dim testStrings() As String = New String() {}
    Dim formattedNumber As Double = bestMatch(testStrings)
    

See Also

Tasks

How to: Assign One Array to Another Array (Visual Basic)

How to: Change an Array to a Different Array (Visual Basic)

How to: Return an Array from a Procedure or Property (Visual Basic)

Troubleshooting Arrays (Visual Basic)

Other Resources

Arrays in Visual Basic