Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Access: Longitude & Latitude in VB
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   16 years ago

Q: I’m new to access and my question is: would you help me to convert decimal latitude and longitude into degrees/minutes/seconds? I want the user to enter a latitude coordinate (47.6913) into a Latitude text box and convert it into degrees/ minutes/seconds/direction (47º 41” 28.8‘ N) and output it in a different text box. Also I would like a another text box for the user to enter a longitude coordinate (122.3144) and the output to a different text box (122º 18” 51.8‘ W). Thanks, Harry


A: Well, if I understand converting from decimal to degress, you take the fractional component (in the case of 47.6913 it would be 0.6913) and multiply it by 60 to get minutes, which would be 41.478. Now take that fraction and multiply by 60... 0.478 x 60 = 28.68 which gives you your seconds. So, the code should look something like this:


MyDecimalValue = 47.6913
MyWholeDegrees = Int(MyDecimalValue) '47
MyRemainder = Round(MyDecimalValue - MyWholeDegrees, 4) '.691
MyMinutes = MyRemainder * 60 '41.477
MyWholeMinutes = Int(MyMinutes) '41
MyRemainder = Round(MyMinutes - MyWholeMinutes, 4) '.478
MySeconds = MyRemainder * 60 '28.68


You'll notice a SLIGHT math error pops up because computers suck (47.6913 - 47 should be .6913 but it's .69129999). You can fix this by rounding off your answers to 4 or 5 decimal places.

Now to get this information into your database, just set up the appropriate fields where needed, and then use an AFTERUPDATE event to populate them. Here's a tutorial on that:

/tips/access/afterupdate-event-vba

Hope this helps. -RR

Comments for Access: Longitude & Latitude in VB
 
Age Subject From
14 yearsVBRichard Rost
14 yearsVBGary

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to Access: Longitude & Latitude in VB
Get notifications when this page is updated
 
 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/28/2024 9:17:05 AM. PLT: 0s
Keywords: vb access longitude latitude tips  PermaLink  Access: Longitude & Latitude in VB