Results 1 to 2 of 2

Thread: Arrays in VB compared to PHP

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229

    Arrays in VB compared to PHP

    Hey,

    In java, C++, or PHP, I would create arrays like

    int MyArr[] = array {value1, 2, 3...}

    I need to make a constant like that in VB. How would I do that?

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Arrays in VB compared to PHP

    You can use Array function in VB in a very simlar way - only array variable would have to ve declared as variant:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim arNumbers As Variant
    3. Dim i%
    4.  
    5.     arNumbers = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
    6.    
    7.     For i = 0 To UBound(arNumbers)
    8.         Debug.Print arNumbers(i)
    9.     Next i
    10.  
    11. End Sub
    Also, here is a quote from MSDN:
    Array Function

    Returns aVariant containing anarray.

    Syntax

    Array(arglist)

    The required arglistargument 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 thevariable name followed by parentheses containing an index number indicating the desired element. In the following example, the firststatement 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 anduser-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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width