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.

  • 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.

  • 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.

  • 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.

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

Related Searches


Promoted By Zergnet


You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!