Arrays and Functions in VB6
From Free Knowledge Base- The DUCK Project: information for everyone
Passing Arrays to Sub Routines and Functions
Simple code example:
Option Explicit
Private Sub cmdGo_Click() Dim aFruit(9, 1) aFruit(0, 0) = 34 aFruit(0, 1) = "Apples" aFruit(1, 0) = 56 aFruit(1, 1) = "Oranges" aFruit(2, 0) = 4 aFruit(2, 1) = "Peaches" Call DoDisplayIt(aFruit) End Sub Private Sub DoDisplayIt(aFruit) Dim cnt As Integer txtOut.Text = "" For cnt = 0 To 2 txtOut.Text = txtOut.Text & vbCrLf & cnt & ". " & aFruit(cnt, 1) & " (in stock): " & aFruit(cnt, 0) Next cnt End Sub
Arrays are passed to procedures "By Value" by default in Visual BASIC. By Value means that the pointer is being passed, not the actual values. So if the Array value is modified in the procedure, it is also modified from the code after where the procedure is called. Visual Basic will not allow you to pass the value of an Array to a procedure "By Value."