Array help

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)
 
R

Robinson

Try:


Dim locations(2) As MapPoint.Location

or.....

Dim locations as New List(Of MapPoint.Location)

locations.Add (obj.Map............ etc.)
 
A

Andrew Backer

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
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top