1 Dimension array problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: 1 Dimension array problem

  1. #1
    Join Date
    Jan 2013
    Posts
    1

    1 Dimension array problem

    Im utilising a 3rd party web service. One of the functions (called PerformAction) accepts a parameter of type myObject.

    Code:
    Dim myObject As Object
    PerformAction(myObject)
    This gave me the error "Value of type 'myObject' cannot be converted to '1-dimensional array of myObject'."

    So i changed the declaration to

    Code:
    Dim myObject(0) As Object
    That resolved the problem, for testing purposes but how could i pass in other values that are not known until runtime? e.g.

    Code:
    Dim myObject(0) As Object
    Code:
    Dim myObject(1) As Object
    Code:
    Dim myObject(2) As Object
    Code:
    Dim myObject(3) As Object
    Code:
    Dim myObject(4) As Object
    So if 5 objects are selected at runtime how could i pass those objects to fit the above scenario mainly to ensure the PerformAction performs the required actions for all the elements. Hope this makes sense?

    Thanks

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,851

    Re: 1 Dimension array problem

    An array is one object with 1 or more elements

    Code:
    Dim myObject(4) as Object
    Would define
    myObject(0)
    myObject(1)
    myObject(2)
    myObject(3)
    myObject(4)

    You can use redim to change the number of elements at runtime.

    Code:
    ReDim myObject(10)
    This will erase any values stored in the array. If values need to be retained then you can use the Preserve keyword

    Code:
    ReDim Preserve myObject(10)
    Always use [code][/code] tags when posting code.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center