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?
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.
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.
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.
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.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With