View Full Version : New Member - Needs help !

09-30-2009, 05:17 AM
Hello All,

Am new to MapPoint and all its features. I am running VB 2008 on Vista and have the European Map installed. I have enabled the COM object in VB and can insert a Map Object onto a windows form.
If I assign a newMap to the mapobject and run the form, it works fine and a form with a map appears.

The problem comes when I want to connect to a csv file and some data.

I am getting errors associated with the importData method.

My Code form the simple form is;

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub
Sub OpenDataSet()

Dim objDataSets As MapPoint.DataSets
Dim objDataSet As MapPoint.DataSet
Dim zDataSource As String

zDataSource = "C:\myData.csv"
objDataSets = AxMappointControl1.ActiveMap.DataSets
objDataSet = objDataSets.ImportData(zDataSource, , , MapPoint.GeoDelimiter.geoDelimiterDefault, 1)
objDataSet.Symbol = 20

End Sub
End Class

The error I get is "No matching method defined for these fields." as below;

System.Runtime.InteropServices.COMException was unhandled
Message="No matching method defined for these fields."
at MapPoint.DataSets.ImportData(String DataSourceMoniker, Object ArrayOfFields, GeoCountry Country, GeoDelimiter Delimiter, Int32 ImportFlags)
at WindowsApplication1.Form1.OpenDataSet() in C:\Users\JMATS\Documents\Visual Studio 2008\Projects\MapPoint\MapPoint\Form1.vb:line 17
at WindowsApplication1.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\JMATS\Documents\Visual Studio 2008\Projects\MapPoint\MapPoint\Form1.vb:line 6
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Mattys Consulting
09-30-2009, 08:38 AM
Hi Martrum,

C# expects all parameters to be filled in; they are not optional.
You have the choice of using Type.Missing or creating an array
that will define the fields. For instance, let's say you have 4 fields:

object[,] oFields = new object[4, 2];
object oPKey = "ID";
object o1 = "Name", o2 = "Latitude", o3 = "Longitude";

oFields[0, 0] = "ID";
oFields[0, 1] = MapPoint.GeoFieldType.geoFieldName;
oFields[1, 0] = "Name";
oFields[1, 1] = MapPoint.GeoFieldType.geoFieldInformation;
oFields[2, 0] = "Latitude";
oFields[2, 1] = MapPoint.GeoFieldType.geoFieldLatitude;
oFields[3, 0] = "Longitude";
oFields[3, 1] = MapPoint.GeoFieldType.geoFieldLongitude;

These are passed in as parameters here:
objDataSets.ImportData(zDataSource, Type.Missing, oFields, MapPoint.GeoDelimiter.geoDelimiterDefault, 1)

I copied and pasted - it might need something ...

Mike Mattys
Mattys Consulting Maps & Custom Programming (http://www.mattysconsulting.com)

09-30-2009, 07:22 PM
Hi thanks for your reply - but i'm using VB ?

What I can't work out now is how to actually get to the data and use it !

I think my code should be something like that below - please advice as to how I loop round the data:

Dim objDataSets As MapPoint.DataSets
Dim objDataSet As MapPoint.DataSet
Dim zDataSource As String
Dim myLong As String
Dim myLat As String
Dim myName As String
Dim location As MapPoint.Location
Dim pushpin As MapPoint.Pushpin
Dim objField As MapPoint.Field

zDataSource = "C:\myData.csv"
objDataSets = AxMappointControl1.ActiveMap.DataSets
objDataSet = objDataSets.LinkData(zDataSource, "long", , , MapPoint.GeoDelimiter.geoDelimiterComma)
objDataSet.Symbol = 20

For Each objField In objDataSet.Fields
myLong = what ?
myLat = what?
myName = what ?
location = AxMappointControl1.ActiveMap.GetLocation(myLong, myLat)
pushpin = AxMappointControl1.ActiveMap.AddPushpin(location, myName)
pushpin.BalloonState = MapPoint.GeoBalloonState.geoDisplayName
pushpin.Symbol = 329
Next objField

09-30-2009, 08:36 PM
You are using .NET and COM Interop, so I believe the advice still applies (you'll note I also gave the same advice to your cross-posting on Microsoft's Bing Maps development forum!).

Also, VB.NET and VB6/VBA are NOT the same. There are quite a few differences as Microsoft made VB into a "proper" object oriented language and not the half-hearted inconsistent attempt that VB6 was. Cutting & pasting VB6 examples generally will not work. So I would also recommend getting up to speed on VB.Net.

(Visual Studio 6 was the last version to support Visual Basic 6. All later versions use VB.NET, and Microsoft dropped support for VB6 a few years ago)


10-01-2009, 10:56 AM
Hi Mike,

I have managed to create an Array as suggested to define the data. But what now ?

How do I display each position on the map ? What am I going to loop through ?

Dim objDataSets As MapPoint.DataSets
Dim objDataSet As MapPoint.DataSet
Dim zDataSource As String
Dim myLong As String
Dim myLat As String
Dim myName As String
Dim location As MapPoint.Location
Dim pushpin As MapPoint.Pushpin
Dim objField As MapPoint.Field

Dim xFieldArray(0 To 2, 0 To 1) As Object

'Use the Name field as the name:
xFieldArray(0, 0) = "long"
xFieldArray(0, 1) = MapPoint.GeoFieldType.geoFieldLongitude
'Use the Address field as data:
xFieldArray(1, 0) = "lat"
xFieldArray(1, 1) = MapPoint.GeoFieldType.geoFieldLatitude
'Use the name field as the Name:
xFieldArray(2, 0) = "name"
xFieldArray(2, 1) = MapPoint.GeoFieldType.geoFieldName

zDataSource = "C:\myData.csv"
objDataSets = AxMappointControl1.ActiveMap.DataSets
objDataSet = objDataSets.LinkData(zDataSource, "name", xFieldArray, MapPoint.GeoCountry.geoCountryUnitedKingdom, MapPoint.GeoDelimiter.geoDelimiterComma)