Arrays hold multiple values. They are variables that can be used to iterate through a list of values. When programming in Visual Basic, using arrays is a common process. The programmer can pass arrays to functions and subroutines where the code prints or manipulates the values. Passing arrays to a subroutine or function only takes a few extra lines of code.
Define the array variable. An array is defined like any other variable except it uses parenthesis. The following is how to define an array that holds 3 values.
ReDim myArrayvariable(3) As String
Assign variables for each index of the array. In programming, an array index starts with the number 0. The following code assigns values for the array.
myArrayvariable(0) = "1"
myArrayvariable(1) = "2"
myArrayvariable(2) = "3"
Create the subroutine that accepts the passed variable. The parameter inside the "myRoutine" subroutine indicates that it requires an array variable. This subroutine iterates through each element of the array and prints it to the debug window.
Sub myRoutine (myInArray( ) As String)
Dim j as Integer
For j=1 to 3
Debug.Print myInArray( j )
Pass the array to the subroutine created in step 3. This statement calls the subroutine and passes the array variable created in step two.
How to Find the Largest Value in an Array in Visual Basic
A Visual Basic array is a data structure that allows you to store a list of values. Arrays can store any data...
How to Use Arrays in Visual Basic
Arrays provide programmers with a method of assigning several values within one variable name. The technique is used when you have a...
How to Transfer Excel VB Data From Range to Array
An array is a data structure that enables you to work with sets of data values in a single structure rather than...
How to Find the Maximum Value in an Array in Visual Basic
Arrays are variables used in programming to hold a list of numbers or characters. Finding the maximum number value in an array...
How Do Pass By Value and Pass By Reference Work in Visual Basic?
Procedures in Visual Basic usually require some data from the program in order to perform their task. The functions receive the data...
How to Pass Information From One Visual Basic Application to Another
There are a variety of ways to pass information between different Visual Basic applications. These range in complexity from simply copying information...
How to Assign a Row Count to a Variable Using Visual Basic
The Visual Basic programming language from Microsoft provides a variety of functions for assigning row counts from arrays to a variable. However,...
How to Find a Character in a String in Visual Basic
Finding a character in a string can seem like a pretty daunting task if you don't know the right tools to use....
How to Write an Array to a File in Visual Basic
File manipulation is often an integral part of software development. In Visual Basic programming, you use the StreamWriter class to create an...
How to Use a Subroutine in Excel Visual Basic
Microsoft Excel's programming language, Visual Basic for Applications (VBA), is a powerful tool that is accessible to anyone, including non-programmers. With macros...