| | Sylvain 11-20-2002, 02:24 PM Hi everyone,
MapPoint 2002, VB6
I’m using the map to show live vehicle with, for each vehicle, a different pushpin and each vehicle bellows to its own datasets. (Vehicle “Truck1”, with its bread crumps, is part of dataset “Truck1” with a different pushpin name for each of its bread crumps).
Everything works fine until I use the “Find” command on the navigation toolbar, the “Find” form of MapPoint starts to blink and is not accessible.
I trap the error “-2147418111 : Method 'DataSets' of object '_Map' failed”. If I click on the map or on VB, it gives me the famous “switch to” message.
In the program, if I do a “resume next”, it’s doing the same. This error only occurs when I click the find and occurs with one or many live vehicle on the map. Is there anyway of trapping the click event on the “Find”? Any help/suggestions will be welcome.
Sylvain Sylvain 11-20-2002, 03:45 PM Take two,
I’ve change my code to use the “FindPushpPin” instead of “QueryAllRecords” and I still have the same problem with the “Find” of navigation toolbar with a similar error message.
Sylvain John Meyer 11-20-2002, 04:59 PM I think you will have to post the code behind your find button before we can help you debug it. Sylvain 11-20-2002, 05:22 PM Hi John,
The code I use with the DataSet is:
Set objRecordset = pubMap.DataSets(VehicleInfo(Index).VehicleNm).Quer yAllRecords
and it the problem occurs on the "Set".
I've change my code to use the the following
Set objPushPin = pubMap.FindPushpin(VehicleInfo(Index).VehicleNm)
and same thing happen on the 'Set'. The code works fine until I click on the 'Find' of the 'Navigation Toolbar'. I've also reinstall MapPoint and the same thing. I test it on 2 computers without a programming environment and the same error.
Sylvain John Meyer 11-20-2002, 10:31 PM Here are two samples. Lets say your Dataset was named Test and your pushpin was named Home.
Dim objMap As MapPointctl.Map
Set objMap = MappointControl1.ActiveMap
Dim objDataSet As MapPointctl.DataSet
Dim objRecords As MapPointctl.Recordset
Set objDataSet = objMap.DataSets("Test")
Set objRecordset = objDataSet.QueryAllRecords
'//////////////////////////////////////////////////////
Dim objPin As MapPointctl.Pushpin
Set objPin = objMap.FindPushpin("Home") Sylvain 11-21-2002, 11:04 AM Hi John,
Thank you for taking the time, I've changed the code to use the dataset again and used the following code:
Dim objRecordset As MapPointctl.Recordset
Dim objDataSet As MapPointctl.DataSet
Set objDataSet = pubMap.DataSets(VehicleInfo(Index).VehicleNm)
Set objRecordset = objDataSet.QueryAllRecords
Again the same problem on the first 'set'. I'm sorry for repeating myself but this code works for hours without a problem and the only problem is when the 'Find' of the toolbar is used.
I've added the following to look at the dataset, the proper name shows but again the same error occurs when I used the find. The error stop on the 'For'.
For intCnt = 1 To pubMap.DataSets.Count
Debug.Print pubMap.DataSets(intCnt).Name
Next
Sylvain John Meyer 11-21-2002, 01:54 PM Sylvain,
When you hit the "Find" button, what information are you passing to your code?
What is VehicleNm? Is that a pushpin?
In one of your posts you mentioned a dataset named "Truck1"
If that is the name of a dataset on your map, you could use the following to set a reference to dataset "Truck1"
Set objDataSet = pubMap.DataSets("Truck1")
'This sample might help.
Dim objMap As MapPointctl.Map
Set objMap = MappointControl1.ActiveMap
Dim objDataSet As MapPointctl.DataSet
Dim objRecords As MapPointctl.Recordset
Set objDataSet = objMap.DataSets("Truck1")
Set objRecordset = objDataSet.QueryAllRecords
Do While Not objRecordset.EOF
Debug.Print objRecordset.Pushpin.Name
objRecordset.MoveNext
Loop Sylvain 11-21-2002, 02:43 PM Hi John,
THis following code is a sub set of what I use. Just create a form, add 2 command button, a timer, and a mapcontrol. A lot of comments were removed to it smaller.
The command1 starts the timer, the timer displays icons with 5 bread crumbs, click on the find of the toolbar and wait 5 seconds. (Please tell me you have the same error.)
Thanks,
Sylvain
Option Explicit
Public pubMap As MapPointCtl.Map
Public privPushPinName As String
Public privRecCnt As Integer
Public Sub subDataSetExist(ByVal pDataSetName As String)
Dim boolDataSetFound As Boolean
Dim intCnt As Integer
boolDataSetFound = False
For intCnt = 1 To pubMap.DataSets.Count
If pubMap.DataSets(intCnt).Name = pDataSetName Then
boolDataSetFound = True
Exit For
End If
Next
' If the Data Set was not found, create the Data Set
If Not boolDataSetFound Then
pubMap.DataSets.AddPushpinSet pDataSetName
End If
End Sub
Private Sub Command1_Click()
privRecCnt = 0
subDataSetExist privPushPinName
Me.Timer1.Interval = 5000
Me.Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Me.Timer1.Enabled = False
Me.Timer1.Interval = 0
End Sub
Private Sub Form_Load()
privPushPinName = "Truck"
Me.MappointControl1.NewMap (geoMapNorthAmerica)
Set pubMap = Me.MappointControl1.ActiveMap
pubMap.Application.Toolbars.Item("Navigation").Visible = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not (pubMap Is Nothing) Then
pubMap.Saved = True
pubMap.Application.Quit
End If
End Sub
Private Sub Timer1_Timer()
Dim objLoc As MapPointCtl.Location
Dim objPushPin As MapPointCtl.Pushpin
Dim objRecordset As MapPointCtl.Recordset
Dim objDataSet As MapPointCtl.DataSet
Dim dblLatitude As Double
Dim dblLongitude As Double
Dim lngX As Long
Dim lngY As Long
Dim intBreadCrumbs As Integer
Dim strTemp As String
privRecCnt = privRecCnt + 1
dblLatitude = CDbl(45.56868)
dblLongitude = CDbl(-73.60147)
' Just to move the Icon
dblLatitude = dblLatitude + CDbl(privRecCnt / 1000)
dblLongitude = dblLongitude + CDbl(privRecCnt / 1000)
' Retrieve the Dataset for this vehicle
Set objDataSet = pubMap.DataSets(privPushPinName)
Set objPushPin = Nothing
' Use to query all the records
Set objRecordset = objDataSet.QueryAllRecords
' Go to the first one, just in case...
objRecordset.MoveFirst
' Retrieve the vehicle in the DataSet
Do While Not objRecordset.EOF
If objRecordset.Pushpin.Name = privPushPinName Then
Set objPushPin = objRecordset.Pushpin
Exit Do
End If
objRecordset.MoveNext
Loop
If Not (objPushPin Is Nothing) Then
intBreadCrumbs = privRecCnt Mod 5
' Create a Unique Name for the Vehicle Push Pin
strTemp = "Crumbs " & CStr(intBreadCrumbs) & " of " & privPushPinName
objRecordset.MoveFirst
Do While Not objRecordset.EOF
' The bread crumbs name was found
If objRecordset.Pushpin.Name = strTemp Then
' Delete this pushpin before changing the name of the original one
' to that Bread Crumbs.
objRecordset.Pushpin.Delete
Exit Do
End If
objRecordset.MoveNext
Loop
objPushPin.Name = strTemp
End If
With pubMap
Set objLoc = .GetLocation(dblLatitude, dblLongitude)
' Add the pushpin to the Original name.
Set objPushPin = .AddPushpin(objLoc, privPushPinName)
End With
objPushPin.BalloonState = geoDisplayName
objPushPin.MoveTo pubMap.DataSets.Item(privPushPinName)
lngX = pubMap.LocationToX(objLoc)
lngY = pubMap.LocationToY(objLoc)
If (lngX < 0 Or lngX > pubMap.Width) Or (lngY < 0 Or lngY > pubMap.Height) Then
objPushPin.Location.GoTo
End If
Set objPushPin = Nothing
Set objDataSet = Nothing
Set objRecordset = Nothing
End Sub John Meyer 11-21-2002, 05:05 PM Sylvain,
I have only looked at the code for a few moments but I have to ask you why is it nessasary to run the code within the Timer1 Control EVERY 5000 milliseconds (12 times per second)?
I think maybe you are overloading the system?
What version of windows are you running? If you have NT/Win2000/XP I would be intrested to see CPU usage as time goes on after you start this Timer Control.
Please let me know what you think. Sylvain 11-22-2002, 09:38 AM John, it works on 98/ME/NT/XP with other application running at the same time. I never used a timer before but I did not find it to be that bad on CPU. So far, it never created a problem or conflict with other apps.
The test I send you was every 5 seconds just for testing; the live system retrieve the information from 1 to 6 times a minute, depending how often the user has to see the information.
The timer is just one way of avoiding doing a push from the server to the client. The real code retrieves the records from a SQL server every elapse time.
Sylvain John Meyer 11-23-2002, 06:28 AM Sylvain,
Ok, I ran the sample code and it does that same thing here. Really wierd. I've tried several things but nothing is working yet. Will let you know if I come up with an idea. kdybvik 11-25-2002, 11:11 AM The "Find" Dialog looks like it wants to be sort of modal. By detecting if a window with "Find" as a title is currently visible at the top of the timer event seems to prevent the problem.
A bit of a hack, but with a bit of extra work it might be acceptable. Localization will be an issue.
Another approach that would take some research would be to try to track down the window handle of the mappoint control and subclass for the desired messages.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Function IsFindVisible() As Boolean
Dim lHwnd As Long
Dim lRet As Long
IsFindVisible = False
lHwnd = FindWindow(vbNullString, "Find")
If (lHwnd <> 0) Then
If (GetParent(lHwnd) = Me.hwnd) And (IsWindowVisible(lHwnd)) Then
IsFindVisible = True
End If
End If
End Function
and as the first executable line in the Timer event
If IsFindVisible() Then Exit Sub John Meyer 11-26-2002, 07:12 PM Sylvain,
Did the post by: kdybvik do the trick for you? Sounds like it might be a good solution. Let us know if it worked out for you. Sylvain 11-28-2002, 07:08 AM Yes John, I just finished trying it and it works fine.
Thanks for all your help, it was appreciated.
Sylvain | |