J
Jonas
I can't seem to get my code to work. My Excel program uses MS Mappoint
to get latitude and longitude. I only want the latitude and longitude
when the results quality is "geoFirstResultGood" otherwise I want the
cell to be skipped. I thought that if I put the word "then" after the
line "If objApp.ActiveMap.FindAddressResults(straddress, City,
state).ResultsQuality = geoFirstResultGood," and the word "else" at the
bottom of the program, like this:
".....ActiveCell.Offset(intCounterT, 6).Value = dblLon
intCounterT = intCounterT + 1
Loop
Else
intCounterT = intCounterT + 1
Loop
That didn't work. Below is block of code that I have been working
with. Hopefully you will be able to tell me what I am not
understanding; I'm stumped.
"Sub TheprogramGetAddressandLatitude()
Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objLoc As MapPoint.Location
Dim strDir As String * 1
Dim dblLat As Double
'Set up the application
Set objMap = objApp.ActiveMap
objApp.Visible = True
objApp.UserControl = True
Range("B1").Activate
intCounterT = 1
Do While ActiveCell.Offset(intCounterT, 0) <> ""
straddress = ActiveCell.Offset(intCounterT, 1)
City = ActiveCell.Offset(intCounterT, 2)
state = ActiveCell.Offset(intCounterT, 3)
'Test if good address
If objApp.ActiveMap.FindAddressResults(straddress, City,
state).ResultsQuality = geoFirstResultGood Then MsgBox "this is a good
address."
'Find an address
Set objLoc = objMap.FindAddressResults(straddress, City, state)
'Get latitude of this location
dblLat = objLoc.Latitude
'Get longitude of this location
dblLon = objLoc.Longitude
'If the latitude is positive, set direction to North
If dblLat > 0 Then
strDir = "N"
'If the latitude is negative, set direction to South
ElseIf dblLat < 0 Then
strDir = "S"
'Set blank if the latitude is zero
Else
strDir = ""
End If
'Display the latitude with degree symbol and N/S
MsgBox "Latitude: " + Format(Abs(dblLat), "0.00000") + Chr(176) +
strDir
ActiveCell.Offset(intCounterT, 5).Value = dblLat
MsgBox "longitude " & dblLon
ActiveCell.Offset(intCounterT, 6).Value = dblLon
intCounterT = intCounterT + 1
Loop
End Sub"
Your response is appreciated.
to get latitude and longitude. I only want the latitude and longitude
when the results quality is "geoFirstResultGood" otherwise I want the
cell to be skipped. I thought that if I put the word "then" after the
line "If objApp.ActiveMap.FindAddressResults(straddress, City,
state).ResultsQuality = geoFirstResultGood," and the word "else" at the
bottom of the program, like this:
".....ActiveCell.Offset(intCounterT, 6).Value = dblLon
intCounterT = intCounterT + 1
Loop
Else
intCounterT = intCounterT + 1
Loop
That didn't work. Below is block of code that I have been working
with. Hopefully you will be able to tell me what I am not
understanding; I'm stumped.
"Sub TheprogramGetAddressandLatitude()
Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objLoc As MapPoint.Location
Dim strDir As String * 1
Dim dblLat As Double
'Set up the application
Set objMap = objApp.ActiveMap
objApp.Visible = True
objApp.UserControl = True
Range("B1").Activate
intCounterT = 1
Do While ActiveCell.Offset(intCounterT, 0) <> ""
straddress = ActiveCell.Offset(intCounterT, 1)
City = ActiveCell.Offset(intCounterT, 2)
state = ActiveCell.Offset(intCounterT, 3)
'Test if good address
If objApp.ActiveMap.FindAddressResults(straddress, City,
state).ResultsQuality = geoFirstResultGood Then MsgBox "this is a good
address."
'Find an address
Set objLoc = objMap.FindAddressResults(straddress, City, state)
'Get latitude of this location
dblLat = objLoc.Latitude
'Get longitude of this location
dblLon = objLoc.Longitude
'If the latitude is positive, set direction to North
If dblLat > 0 Then
strDir = "N"
'If the latitude is negative, set direction to South
ElseIf dblLat < 0 Then
strDir = "S"
'Set blank if the latitude is zero
Else
strDir = ""
End If
'Display the latitude with degree symbol and N/S
MsgBox "Latitude: " + Format(Abs(dblLat), "0.00000") + Chr(176) +
strDir
ActiveCell.Offset(intCounterT, 5).Value = dblLat
MsgBox "longitude " & dblLon
ActiveCell.Offset(intCounterT, 6).Value = dblLon
intCounterT = intCounterT + 1
Loop
End Sub"
Your response is appreciated.