View Full Version : AddPolyline problems, any ideas?

09-25-2013, 04:12 PM
I am really stuck and would welcome any ideas!
I am using VBA (running in Excel) to add a polyline to mappoint - or failing in fact
I want add the polyline around an array of mappoint locations stored in (MPLoc(0), MPLoc(1) etc) which I have already created.
I have confirmed the locations are good and can add separate lines on mappoint to join them, but I need a polyline.
I don't know when coding how many locations I will have, so I cannot hard code the array of locations.

this is the line that stops...

Set mShape = gobjMap.Shapes.AddPolyline(MPLoc) <- this is the line at which the debugger stops with "Parameter not correct"

mShape.ZOrder (geoSendBehindRoads)

any ideas welcome!

Eric Frost
09-25-2013, 04:35 PM
John, great to see you participating in the forums! It's been slightly more than two years? Search Results - MapPoint Forums (http://www.mapforums.com/search.php?do=finduser&userid=4993&contenttype=vBForum_Post&showposts=1) LOL.

My first thought: try starting with MPLoc(1) e.g. "MPLoc(1), MPLoc(2) etc"

09-26-2013, 03:46 AM
Thanks Eric, good to be back - new job etc!

It works (ie draws the polyline) when I put it as "array(MPLoc(1), MPLoc(2) etc)" but I am don't know how many locations I will have on the polyline when coding so, ideally, I want to pass the location array and then get the polyline drawn from that. Any way of doing that or doing a workaround?

I kind of have the feeling I am being pretty dim, but cannot work out a way to this (short of creating hundreds of arrays for every number of mappoint locations I am ever likely to call and then picking the right one when the number of locations are known)

Eric Frost
09-26-2013, 10:39 AM
You can Redim to change the number of elements in an array. I don't do this every day, but I'll take a stab at how it might look if the locations are in a dataset:

Sub Main
Dim MPLocs() As MapPoint.Location
Dim PPCount As Integer
Dim DS As MapPoint.Dataset
Dim RS As MapPoint.Recordset

Set DS = MAP.Datasets("Polyline Vertices")
PPCount = DS.Count

Redim MPLocs(1 to PPCount)

Set RS = DS.QueryAllRecords

Dim i As Integer
i = 1
Do While Not RS.EOF
Set MPLocs(i) = RS.Pushpin.Location
i = i + 1

'then finally
Set mShape = MAP.Shapes.AddPolyline(MPLocs)
End Sub

(code not tested)

See if you can find some more examples here --

https://www.google.com/search?q=site%3Amapforums.com+Redim+MapPoint+Locat ion

Hope this helps! and Congrats on the new job! :clap:

10-04-2013, 09:11 AM
Thanks Eric
One problem of a new job is finding time to use your suggestion - not yet: but many thanks for putting it up!
If I understand your suggested method I create the pushpins, put them in dataset "Polyline Vertices" and then use that dataset to define some new locations which will be the points on the polyline? Definitely not tried that, I will come back when I have. Thanks

Eric Frost
10-04-2013, 12:22 PM
Well, you wouldn't need to create a dataset and put Pushpins in there, I was just using that as an example so I could get a Count and have something to loop over... if you are looping over a Access query or something that would be fine too as long as you can get the count so you can Redim.


10-07-2013, 11:20 AM
It works! Thanks for your help
The problem was redim-ing wrongly:
I had
redim MPLoc(count)

(count being the number of locations on the polyline)... for which the polyline method throws error of "parameter incorrect"
as per Eric's code I should have done

redim MPLoc (1 to count)

Now works fine. That was hard work!
As you said, I did not need the datasets code as I knew how many locations there were already
I saw quite a few posts around the internet asking about this error message and no solutions suggested, so silly as it is, this may be useful to more people than me.