Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB6 - Defining a String Array

Tags:

arrays

syntax

vb6

I need to use VB6 and I'm struggling with a few basic tasks.

When I define an array in C# for example:

string[] s = {"a", "b", "c", "d" };

But in VB6, I've been doing this:

Dim s(0 To 3) As String
s(0) = "a"
s(1) = "b"
s(2) = "c"
s(3) = "d"

Is there a more efficient way of defining an array in VB6 than the example I illustrated above? A way similar to the C# approach?

like image 261
Loren Kuich Avatar asked Jul 03 '13 08:07

Loren Kuich


People also ask

How do you declare an array in VB6?

In VB6 an array is a variable that contains a finite number of elements that have a common name and data type. Each element of an array is identified by a unique index number. Changes made to one element of an array don't affect the other elements. The Individual elements of an array are identified using an index.

How do you declare an array in Visual Basic?

In visual basic, Arrays can be declared by specifying the type of elements followed by the brackets () like as shown below. Dim array_name As [Data_Type](); Here, array_name represents the name of an array and Data_type will represent the data type of elements to store in an array.

What is the best way to initialize an array in Visual Basic?

To initialize an array variable by using an array literalEither in the New clause, or when you assign the array value, supply the element values inside braces ( {} ). The following example shows several ways to declare, create, and initialize a variable to contain an array that has elements of type Char .

What is dynamic array in VB6?

A Dynamic array is used when we do not know how many items or elements to be inserted in an array. To resolve this problem, we use the dynamic array. It allows us to insert or store the number of elements at runtime in sequentially manner.


1 Answers

Dim s
s = Array("a", "b", "c", "d")
like image 200
Anderson Avatar answered Oct 20 '22 22:10

Anderson