hotwheels
Mar 20th, 2009, 11:45 AM
I am beginning to work with the MapPoint 2009 ActiveX control. The sample code was written in VB 6 and some samples do not appear to have the correct syntax for VB 8. Can anyone explain this?
[Microsoft Visual Basic 6.0]
Sub ShowOnlySomeFields()
Dim objApp As New MapPoint.Application
Dim objDataSet As MapPoint.DataSet
objApp.Visible = True
objApp.UserControl = True
Set objDataSet = objApp.OpenMap(objApp.Path & "\Samples\Clients.ptm").DataSets(1)
arArray = Array(objDataSet.Fields(1), objDataSet.Fields(2), objDataSet.Fields(3))
'Set which fields will be visible in the Pushpin balloon
objDataSet.SetFieldsVisibleInBalloon arArray
'Show the balloon for the first record
objDataSet.QueryAllRecords.Pushpin.BalloonState = geoDisplayBalloon
End Sub
()
Specifically, the assignment of the array elements using the "fields(x)" syntax does not work.
Any help on this would be appreciated.
si_the_geek
Mar 20th, 2009, 11:53 AM
Welcome to VBForums :wave:
The problem is that VB6 and earlier are actually an entirely different language to VB.Net (VB 2002 and later). There are some similarities, but lots of differences.
I'm pretty sure that the issue here is the Array function, as I doubt that exists in .Net - I think you need to build arArray a different way, but am not sure of the syntax; hopefully somebody else will be able to tell you the details.
techgnome
Mar 20th, 2009, 12:27 PM
How is arArray currently defined in the sample code? I don't see it dimmed any where.
Dim arArray () as object = {objDataSet.Fields(1), objDataSet.Fields(2), objDataSet.Fields(3))
Replace the As Object with the appropriate data type if you can (should be the same as what ever objDataSet.Fields() is.)
-tg
standean
Apr 5th, 2009, 07:10 PM
I was stumped on this too. I got it to work as follows:
Private Sub btnTrucks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrucks.Click
Dim MyMap As MapPoint.Map
Dim GotMap As Boolean
Dim JetSql As String
Dim rsTruck As New ADODB.Recordset
Dim dbCatalog As New ADOX.Catalog()
Dim JetCon As New ADODB.Connection
' they are objects which used to be a variant in vb 6.0
Dim TruckFields(6, 1) As Object
Dim VisibleTruckFields(6) As Object
If GotMap = False Then
AxMappointControl.NewMap(frmMDI.AppDirectory & "NewNorthAmericanMap.ptt")
MyMap = AxMappointControl.ActiveMap
GotMap = True
End If
Try
MyMap.DataSets("Trucks").Delete()
Catch ex As Exception
End Try
Try
dbCatalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\windows\temp\fgoc.mdb")
Catch ex As Exception
End Try
JetCon.Provider = "Microsoft.Jet.OLEDB.4.0"
JetCon.Open("c:\windows\temp\fgoc.mdb")
' here is the table to import
With JetCon
Try
.Execute("DROP TABLE Trucks;")
Catch ex As Exception
End Try
JetSql = "create table Trucks (" & _
"driver_id long, " & _
"driver_name char(35), " & _
"cell_phone char(35), " & _
"day_hours float, " & _
"week_hours float, " & _
"longitude float, " & _
"latitude float, " & _
"destination_1 char(35), " & _
"destination_2 char(35), " & _
"destination_3 char(35), " & _
"product_1 char(35), " & _
"product_2 char(35), " & _
"product_3 char(35), " & _
"truck_id long, " & _
"trailer_id long, " & _
"trailer_desc char(35));"
Try
.Execute(JetSql)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End With
rsTruck.Open("Select * from Trucks;", JetCon, _
ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, 0)
ds_driver.Clear()
sda_driver.Fill(ds_driver, "driver")
' populate the table
For RecCt = 0 To ds_driver.Tables(0).Rows.Count - 1
rsTruck.AddNew()
rsTruck.Update("driver_id", ds_driver.Tables(0).Rows(RecCt).Item("driver_id"))
rsTruck.Update("driver_name", Trim(ds_driver.Tables(0).Rows(RecCt).Item("driver_name")))
rsTruck.Update("cell_phone", Trim(ds_driver.Tables(0).Rows(RecCt).Item("cell_phone")))
rsTruck.Update("day_hours", ds_driver.Tables(0).Rows(RecCt).Item("day_hours"))
rsTruck.Update("week_hours", ds_driver.Tables(0).Rows(RecCt).Item("week_hours"))
rsTruck.Update("longitude", ds_driver.Tables(0).Rows(RecCt).Item("longitude"))
rsTruck.Update("latitude", ds_driver.Tables(0).Rows(RecCt).Item("latitude"))
Next
JetCon.Close()
' these are the individual fields and types
' geoFieldData is something you want in the balloon
' anything else is something that MapPoint uses
TruckFields(0, 0) = "driver_id"
TruckFields(0, 1) = MapPoint.GeoFieldType.geoFieldData
TruckFields(1, 0) = "driver_name"
TruckFields(1, 1) = MapPoint.GeoFieldType.geoFieldName
TruckFields(2, 0) = "cell_phone"
TruckFields(2, 1) = MapPoint.GeoFieldType.geoFieldData
TruckFields(3, 0) = "day_hours"
TruckFields(3, 1) = MapPoint.GeoFieldType.geoFieldData
TruckFields(4, 0) = "week_hours"
TruckFields(4, 1) = MapPoint.GeoFieldType.geoFieldData
TruckFields(5, 0) = "longitude"
TruckFields(5, 1) = MapPoint.GeoFieldType.geoFieldLongitude
TruckFields(6, 0) = "latitude"
TruckFields(6, 1) = MapPoint.GeoFieldType.geoFieldLatitude
' import the table
Try
MyMap.DataSets.ImportData("c:\windows\temp\fgoc.mdb!Trucks", _
ArrayOfFields:=TruckFields, _
ImportFlags:=MapPoint.GeoImportFlags.geoImportAccessTable)
Catch ex As Exception
MsgBox(ex.Message)
End Try
MyMap.DataSets("Trucks").Symbol = 33
' here is where you show them or not
' the array is base 0 and the dataset is base 1
' DAMN YOU BILL GATES!!!
VisibleTruckFields(0) = MyMap.DataSets("Trucks").Fields(1)
VisibleTruckFields(1) = MyMap.DataSets("Trucks").Fields(2)
VisibleTruckFields(2) = MyMap.DataSets("Trucks").Fields(3)
VisibleTruckFields(3) = MyMap.DataSets("Trucks").Fields(4)
VisibleTruckFields(4) = MyMap.DataSets("Trucks").Fields(5)
VisibleTruckFields(5) = MyMap.DataSets("Trucks").Fields(6)
VisibleTruckFields(6) = MyMap.DataSets("Trucks").Fields(7)
MyMap.DataSets("Trucks").SetFieldsVisibleInBalloon(VisibleTruckFields)
AxMappointControl.SaveMapAs(frmMDI.AppDirectory & "DispatchMap.ptm")
MsgBox("Done!")
End Sub