Results 1 to 4 of 4

Thread: [RESOLVED] creating and using array

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    Resolved [RESOLVED] creating and using array

    did a search and
    i checked out "original monkey gangeter's tutorial on arrays. Followed it to the T and im not getting what i want.

    from what i understand to create an array id do this

    dim arrayname(#) as datatype

    arrayname(0)= "whatever value i want"
    arrayname(1)= "whatever i want"
    ... so on

    this doesnt work on mine, the bottome two arrayname's would be underlined in blue and it would say "explicit initialization is nto permitted with arrays declared with excplicit bounds" i have this declared as at the module level, does it belong somehwere else?

    and then

    how do i specify which element in the array i want using a combo box SelectedIndexChange?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,439

    Re: creating and using array

    I'm guessing that you have those lines outside of any method definition. You can declare and initialise an array outside a method, which is what your first line does, but to set individual elements you must do it inside a method. You can do this:
    VB Code:
    1. Dim myArray(upperBound) As Object
    2.  
    3. Private Sub SomeMethod()
    4.     myArray(0) = someObject
    5.     myArray(1) = someOtherObject
    6.     '...
    7. End Sub
    or this:
    VB Code:
    1. Dim myArray() As Object = {someObject, someOtherObject, ...}
    Note in the second example I have not specified an upper bound. When you initialise an array at the time it's declared you cannot specify an upper bound as it is controlled by the size of the array you use to initialise it with.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    Re: creating and using array

    gotcha thanks

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,439

    Re: creating and using array

    Don't forget to resolve your thread from the Thread Tools menu if you have a satisfactory answer.

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