Array help

  • Thread starter Thread starter Marc
  • Start date Start date
M

Marc

Anyone know why the below array doesnt work?


Dim locations() As MapPoint.Location
Set locations(1) = objMap.FindResults("Los Angeles, California")(1)
Set locations(2) = objMap.FindResults("Honolulu, Hawaii")(1)
Set locations(3) = objMap.FindResults("Tokyo, Japan")(1)


Dim oShp As MapPoint.Shape
Set oShp = objMap.Shapes.AddPolyline(locations)
 
Try:


Dim locations(2) As MapPoint.Location

or.....

Dim locations as New List(Of MapPoint.Location)

locations.Add (obj.Map............ etc.)
 
It does not work because you have not actually allocated an array, just
declared that this variable is of type "array of location".

As the previous poster said, either declare the array size before hand,
or use a list of objects that is of the same type. You might end up
with

System.Collections.Generic.List(Of MapPoint.Location)(3)

where 3 is the initial size you want (you can shorten that declaration
up, for sure!)

After that you can just call the .ToArray() function get the an array
of those objects out, if that is what your function requires.

// Andrew
 
Marc said:
Anyone know why the below array doesnt work?

Dim locations() As MapPoint.Location
Set locations(1) = objMap.FindResults("Los Angeles, California")(1)
Set locations(2) = objMap.FindResults("Honolulu, Hawaii")(1)
Set locations(3) = objMap.FindResults("Tokyo, Japan")(1)

Your code looks like VB6 code. If your question is related to VB6, consider
posting it in one of the groups in the "microsoft.public.vb.*" hierarchy.

BTW: You need to dimension the array prior to using it:

\\\
Dim Locations(0 To n) As MapPoint.Location
///

In VB.NET, 'Set' is not required.
 
Back
Top