Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one declare an array in VBScript?

I used this in Excel and it works fine.

dim varScreen (0 to 2) as string
varScreen(0) = "sample 1"
varScreen(1) = "sample 2"
varScreen(2) = "sample 3"

I am trying to translate this array to VBScript but I keep getting this error:

Line: 14
Error: Expected ')'

I have tried various options, removed as string, dim varScreen as array but I still get the error.

What is the proper syntax?

like image 308
jon rios Avatar asked Mar 28 '15 17:03

jon rios


People also ask

How is an array declared in VBScript?

Declaration of Arrays in VBScript Declaration of an Array can be done in the same manner in which Variables are declared but with the difference that the array variable is declared by using parenthesis '()'. The Dim keyword is used to declare an Array.

How do you declare an array?

To create an array, define the data type (like int ) and specify the name of the array followed by square brackets []. To insert values to it, use a comma-separated list, inside curly braces: int myNumbers[] = {25, 50, 75, 100}; We have now created a variable that holds an array of four integers.

How do you declare an array variable in VB net?

We can declare an array by specifying the data of the elements followed by parentheses () in the VB.NET. In the above declaration, array_name is the name of an array, and the Data_Type represents the type of element (Integer, char, String, Decimal) that will to store contiguous data elements in the VB.NET array.

How do we declare a variable in VBScript?

Declaring Variables Variables are declared using “dim” keyword. Since there is only ONE fundamental data type, all the declared variables are variant by default. Hence, a user NEED NOT mention the type of data during declaration. Example 1 − In this Example, IntValue can be used as a String, Integer or even arrays.


1 Answers

You can also create arrays dynamically using the Array function. Sometimes this is more convenient than assigning array elements separately.

Dim arr
arr = Array("sample 1", "sample2", "sample 3")
like image 192
Helen Avatar answered Oct 14 '22 09:10

Helen