Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 6 of 6

Find distance between two UK postal addresses by using VB

This is a discussion on Find distance between two UK postal addresses by using VB within the MapPoint Desktop Discussion forums, part of the Map Forums category; To response the recent emails and questions that Iíve been asked of What and How Mappoint together with VB/VB.NET/VBA programming ...

  1. #1
    AKPost is offline Junior Member White Belt
    Join Date
    Oct 2003
    Posts
    3

    Find distance between two UK postal addresses by using VB

    To response the recent emails and questions that Iíve been asked of What and How Mappoint together with VB/VB.NET/VBA programming languages can help improve your business by targeting your customers based on the UK geographic location, I have published the following code/tips and alone with a real world scenario that my program is trying to solve. Hope this would help!


    A well-known restaurant chain has 70 odd branches across the UK. The restaurant Management promote its specific seasonal offers in a regular basis for each their branches only to the customer who lives within 2 miles radius distance. For central London however, 0.5 miles of distance is thought to be appropriate for their direct mailing campaign. Overlapping is strictly prohibited, as it would confuse customer if they receive two letters from two different branches.

    More than 50,000 of their customer list was given in a format of MS Excel with full address and the UK postcode.

    A solution was written by using VB.NET that calls an instance of Mappoint to measure the two address one at a time and pick up the qualified record from customer list and then output this record with the store code to a new file.


    The most important measurement is handled by the following syntax;

    Radius = locMaster.DistanceTo(oMap.FindResults(dr("PostCode "))(1))



    Of course, you need to declare all your variables, including create instance of Mappoint at the beginning of your program;

    Dim locMaster As MapPoint.Location

    Ö
    objApp = New MapPoint.Application
    objApp.Units = MapPoint.GeoUnits.geoMiles
    Ö

    I used a loop that loops thru all our customer list by using a SqlDataReader dr().


    While dr.Read

    Radius = locMaster.DistanceTo(oMap.FindResults(dr("PostCode "))(1))

    If Radius <= CType(txtRadius.Text, Double) Then
    txtFileText.Text += strAddress(dr("CustomerID"), dr("Title"), dr("FirstName"), dr("LastName"), dr("Address1"), dr("PostTown"), dr("SubTown"), dr("SubLoca"), dr("County"), dr("PostCode")) & Trim(StoreCode.Text) & vbCrLf
    iFounder = iFounder + 1
    End If

    If CInt(RecodRequired.Text) = i2Founder Then
    Exit While
    End If

    End While
    dr.Close()

    I have also used a loop counter; iFounder to counts how many founds since sometime restaurant requires certain number of records from their list. For example, 200 for central London while 500 for Birminghamís branchÖetc

  2. #2
    AKPost is offline Junior Member White Belt
    Join Date
    Oct 2003
    Posts
    3

    Typoo, sorry

    this should be;

    If CInt(RecodRequired.Text) = iFounder Then

  3. #3
    plank is offline Junior Member White Belt
    Join Date
    Oct 2003
    Posts
    8

    so... whats wrong with this code

    Sub Macro2()
    '
    ' Macro2 Macro
    ' Macro recorded 06/10/2003 by Daniel Fountain
    '
    Dim objApp As MapPoint.Application
    Dim objMap As MapPoint.Map
    Dim objLoc1 As MapPoint.Location
    Dim objLoc2 As MapPoint.Location
    Dim objCenter As MapPoint.Location

    '//open MapPoint and create a new map
    Set objApp = New MapPoint.Application
    objApp.Visible = True
    objApp.UserControl = True
    objApp.Activate
    Set objMap = objApp.NewMap

    objApp.Units = MapPoint.GeoUnits.geoMiles

    objLoc1 = objMap.FindResults("IP1 5HN")(1)
    objLoc1.DistanceTo (objMap.FindResults("IP5 3UT")(1))

    '
    End Sub

    The error is on the "objLoc1 = objMap.FindResults("IP1 5HN")(1)" line and it says "object vairiable or with block object vairable not set"

  4. #4
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    syntex is 2002

    Which version of Mappoint are you installed on your PC? If it's Mappoint 2000 or earlier, FindResult() has to have City/Town string variable and postcode to together for it to work. don't know why.

    mine is MP 2002.

    hope this help.

  5. #5
    plank is offline Junior Member White Belt
    Join Date
    Oct 2003
    Posts
    8
    its MP2002 europe - does the euro bit make a difference to this conversation?

  6. #6
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    close!!

    objLoc1 = objMap.FindResults("IP1 5HN")(1)

    should read

    set objLoc1 = objMap.FindResults("IP1 5HN")(1)

    ;-]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do I get the driving distance of two addresses?
    By dawa in forum MapPoint Desktop Discussion
    Replies: 5
    Last Post: 04-18-2008, 02:23 AM
  2. Find distance between two addresses
    By WonderMonkey in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 06-26-2006, 03:28 PM
  3. Why doesn't it find these addresses?
    By pileggi in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 09-13-2005, 03:01 AM
  4. Calculate Distance Between 2 Street Addresses?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 10-08-2003, 06:16 AM
  5. Postal Addresses To Coordinate
    By Anonymous in forum Wish List
    Replies: 2
    Last Post: 05-06-2003, 10:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27