Question:

Visual basic question?

by  |  earlier

0 LIKES UnLike

Your Open QuestionShow me another »

Visual basic question?

Anybody know how to set up an array with the following information:

Index Value

0 John

1 Mike

2 Sam

3 Tim

 Tags:

   Report

2 ANSWERS


  1. Dim Names(4) As String

    Names(0) = "John"

    Names(1) = "Mike"

    Names(2) = "Sam"

    Names(3) = "Tim"

    -or-

    Dim Names(0 to 3) As String

    Names(0) = "John"

    Names(1) = "Mike"

    Names(2) = "Sam"

    Names(3) = "Tim"


  2. Which version of VB are you using?

    In VB6:

    Syntax

    Array(arglist)

    The required arglist argument is a comma-delimited list of values that are assigned to the elements of the array contained within the Variant. If no arguments are specified, an array of zero length is created.

    Remarks

    The notation used to refer to an element of an array consists of the variable name followed by parentheses containing an index number indicating the desired element. In the following example, the first statement creates a variable named A as a Variant. The second statement assigns an array to variable A. The last statement assigns the value contained in the second array element to another variable.

    Dim A As Variant

    A = Array(10,20,30)

    B = A(2)

    The lower bound of an array created using the Array function is determined by the lower bound specified with the Option Base statement, unless Array is qualified with the name of the type library (for example VBA.Array). If qualified with the type-library name, Array is unaffected by Option Base.

    Note   A Variant that is not declared as an array can still contain an array. A Variant variable can contain an array of any type, except fixed-length strings and user-defined types. Although a Variant containing an array is conceptually different from an array whose elements are of type Variant, the array elements are accessed in the same way.

    Array Function Example

    This example uses the Array function to return a Variant containing an array.

    Dim MyWeek, MyDay

    MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")

    ' Return values assume lower bound set to 1 (using Option Base

    ' statement).

    MyDay = MyWeek(2)   ' MyDay contains "Tue".

    MyDay = MyWeek(4)   ' MyDay contains "Thu".

    Answer:

    .........................................

    Dim FirstName As Variant

    FirstName = Array(John, Mike, Sam, Tim)

    .........................................

    : )
You're reading: Visual basic question?

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.