How to Add to an Array in VBA

Visual Basic for Applications (VBA) is a programming language used in login scripts. Administrators use VBA to program settings for users when they log in to the network. An array is a variable that lets you contain several values in one variable. It is beneficial if you have a long list of values you want to use in your code. You can edit a VBA file using a simple text editor such as Notepad.

Instructions

    • 1

      Right-click the VBS file on the computer and select "Edit." The VBS file code opens. Scroll down the file to the location where you want to add the array.

    • 2

      Type the following code to create an array variable:

      Dim myarray(1 To 10) As String

      This array variable is named "myarray." It can contain up to ten string values.

    • 3

      Assign values to the array. In this example, the first two indexes in the array are assigned colors. The following code is how you assign values to your array:

      myarray(0) = "orange"

      myarray(1) = "blue"

      Notice that the first value in an array is "0." The "0th" index is always the first value in an array.

    • 4

      Click the "File" menu item and select "Save." The changes to the VBA file are saved to the code.

Related Searches

References

You May Also Like

Related Ads

Check It Out

Prep for Black Friday Checklist [Infographic]