matt beamish
Registered User.
- Local time
- Today, 15:56
- Joined
- Sep 21, 2000
- Messages
- 215
Hi people - I am really a clumsy novice with this, especially in dealing with errors, so forgive my ignorance.
I have a form which calls some VBA functions I have found and put together in an Access module, that pass a location textstring to the Google API service and return latitude and longitude results into a control named "latlngcntrl", and then other functions that split "latlngcntrl" into separate lat and lng values ("PHI" and "LAM" ) and then process those results into NGR coordinates for the UK.
The functions I have used were written for Excel vb.
The function that returns the latlong from Google is based on this which I placed in an Access module:
http://policeanalyst.com/using-the-google-geocoding-api-in-excel/http://
The functions that process the split Lat and lng results I found in an Ordnance Survey XLS spreadsheet http://www.ordnancesurvey.co.uk/docs/support/projection-and-transformation-calculations.xls
There are 8 or so constants (Pi, A, B, e0, f0, n0, Phi0, LAM0) used in the Projection calculations and I have stated these globally in a separate module and I am using functions to call the constants into the calculations.
If my textstring is not recognised by Google, my return value for "latlngcntrl" is "Not Found***". However the other functions that use this value continue to try to process it, and so I get errors that I need to learn how to control, and anyone trying to use the form will see several error messages - and I need to avoid this.
I want the other functions to stop running if Google API does not return a latitude/longitude to my control "latlongcntrl" and for a User not to get any error messages other than "Location not recognised".
In the projections code there are several functions that are interdependent.
Here is one of the functions that I have adapted from the Excel VB module, which includes some debug.print statements I included when I was adapting the code.:
What should my conditional statement be to stop the function "unction Lat_Long_to_East" from running and reporting an error, if it could not find one of the two variables "PHI" and "LAM" that it needs?
thanks in advance
I have a form which calls some VBA functions I have found and put together in an Access module, that pass a location textstring to the Google API service and return latitude and longitude results into a control named "latlngcntrl", and then other functions that split "latlngcntrl" into separate lat and lng values ("PHI" and "LAM" ) and then process those results into NGR coordinates for the UK.
The functions I have used were written for Excel vb.
The function that returns the latlong from Google is based on this which I placed in an Access module:
http://policeanalyst.com/using-the-google-geocoding-api-in-excel/http://
The functions that process the split Lat and lng results I found in an Ordnance Survey XLS spreadsheet http://www.ordnancesurvey.co.uk/docs/support/projection-and-transformation-calculations.xls
There are 8 or so constants (Pi, A, B, e0, f0, n0, Phi0, LAM0) used in the Projection calculations and I have stated these globally in a separate module and I am using functions to call the constants into the calculations.
If my textstring is not recognised by Google, my return value for "latlngcntrl" is "Not Found***". However the other functions that use this value continue to try to process it, and so I get errors that I need to learn how to control, and anyone trying to use the form will see several error messages - and I need to avoid this.
I want the other functions to stop running if Google API does not return a latitude/longitude to my control "latlongcntrl" and for a User not to get any error messages other than "Location not recognised".
In the projections code there are several functions that are interdependent.
Here is one of the functions that I have adapted from the Excel VB module, which includes some debug.print statements I included when I was adapting the code.:
Code:
Function Lat_Long_to_East(PHI, LAM, A, B, e0, f0, Phi0, LAM0)
'Project Latitude and longitude to Transverse Mercator eastings.
'Input: - _
Latitude (PHI) and Longitude (LAM) in decimal degrees'; _
ellipsoid axis dimensions (a & b) in meters'; _
eastings of false origin (e0) in meters'; _
central meridian scale factor (f0)'; _
latitude (PHI0) and longitude (LAM0) of false origin in decimal degrees.
Dim RADPHI As Single
Dim RADLAM As Single
Dim RADPHI0 As Single
Dim RADLAM0 As Single
Dim af0 As Single
Dim bf0 As Single
Dim e2 As Single
Dim IV As Single
Dim V As Single
Dim VI As Single
Dim n As Single
Dim nu As Single
Dim rho As Single
Dim eta2 As Single
Dim P As Single
'Convert angle measures to radians
RADPHI = [PHI] * (Pi / 180)
RADLAM = [LAM] * (Pi / 180)
RADPHI0 = [Phi0] * (Pi / 180)
RADLAM0 = [LAM0] * (Pi / 180)
af0 = A * f0
bf0 = B * f0
e2 = ((af0 ^ 2) - (bf0 ^ 2)) / (af0 ^ 2)
n = (af0 - bf0) / (af0 + bf0)
nu = af0 / (Sqr(1 - (e2 * ((Sin(RADPHI)) ^ 2))))
rho = (nu * (1 - e2)) / (1 - (e2 * (Sin(RADPHI)) ^ 2))
eta2 = (nu / rho) - 1
P = RADLAM - RADLAM0
Debug.Print "P="; P
Debug.Print "LAM ="; LAM
Debug.Print "Pi ="; Pi
Debug.Print "A ="; A
IV = nu * (Cos(RADPHI))
Debug.Print "IV="; IV
V = (nu / 6) * ((Cos(RADPHI)) ^ 3) * ((nu / rho) - ((Tan(RADPHI) ^ 2)))
Debug.Print "V="; V
VI = (nu / 120) * ((Cos(RADPHI)) ^ 5) * (5 - (18 * ((Tan(RADPHI)) ^ 2)) + ((Tan(RADPHI)) ^ 4) + (14 * eta2) - (58 * ((Tan(RADPHI)) ^ 2) * eta2))
Debug.Print "VI="; VI
Lat_Long_to_East = e0 + (P * IV) + ((P ^ 3) * V) + ((P ^ 5) * VI)
End Function
What should my conditional statement be to stop the function "unction Lat_Long_to_East" from running and reporting an error, if it could not find one of the two variables "PHI" and "LAM" that it needs?
thanks in advance