Accessing Maptitude from a VBA program

It is possible to work with GISDK classes from VBA. Maptitude provides a COM interface for accessing the GISDK via VBA and other COM client applications.

Here is an example of how you would work with the Routing API:

Set Gisdk = CreateObject("Maptitude.AutomationServer")
coords = Array(Gisdk.Function("Coord", -71206120, 42321660), _
Gisdk.Function("Coord", -71208932, 42349258))
Set router = Gisdk.CreateObject("Routing.Router", "")
router.Set "Minimize", "Distance"
Set path = router.Method("CalculatePath", coords)

The code above creates an instance of the Maptitude Automation Server object, which allows you to interact with Maptitude programmatically. It then uses the Gisdk.Function() method to convert the latitude and longitude into GISDK Coord objects and save them in an VBA array using the VBA Array function. An instance of the Routing.Router object is created, and the Set keyword is used to instruct the router to find the path with the shortest distance between the given coordinates. Finally, it calculates the shortest path. You can also use Get and Method keyword to get properties and call methods on the GISDK object.

The CreateObject method has a 2nd parameter, which is the path to the compiled GISDK user interface (UI) database which contains the class. When the empty string is used, as in the example above the standard Maptitude UI database is referenced, which allows you to create instances of the Maptitude standard classes. You can also create your own GISDK classes, compile them to your UI, and use the 2nd parameter in CreateObject to instance your custom classes.

To access Maptitude from VBA, you would use the References dialog (http://msdn.microsoft.com/en-us/library/office/gg251371(v=office.15).aspx ) to add a reference to the Maptitude Type Library. You can then use all the functionality of the Maptitude Automation Server API to work with Maptitude functionality. The example that we ship in GISDK\Samples\ACTIVEX is most applicable to this scenario.

If you were developing a Microsoft Access add-in in a .NET language, then you could alternatively use the Caliper Form API. Please, refer to Accessing Maptitude from .NET for more information

Example

VERSION 5.00
 Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Form
 Caption = "Form1"
 ClientHeight = 4456
 ClientLeft = 96
 ClientTop = 416
 ClientWidth = 4752
 OleObjectBlob = "ACTIVEXFRM.frx":0000
 StartUpPosition = 1 'CenterOwner
 End
 Attribute VB_Name = "Form"
 Attribute VB_GlobalNameSpace = False
 Attribute VB_Creatable = False
 Attribute VB_PredeclaredId = True
 Attribute VB_Exposed = False
Dim Gisdk As Object
Private Sub Bitmap_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal DragState As MSForms.fmDragState, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
End Sub
Private Sub CommandButton1_Click()
 MapClose
 End
 End Sub
Private Sub UserForm_Initialize()
 Gisdk.RunMacro "MinimizeWindow", "Frame|"
 Gisdk.RunMacro "SetMapUnits", "Miles"

 ' Open the map used by this application
'Note: The map is installed under C:\Users\your_user_name\Documents\Caliper\Maptitude 20YY\Tutorial\, where 20YY is the Maptitude version
 folder = Gisdk.Macro("G30 Tutorial Folder", "")
 Gisdk.RunMacro "OpenMap", folder + "BMP_SVR.MAP", Null
' Change its size to the size required by the client
 Gisdk.RunMacro "SetWindowSizePixels", Null, 600, 600
' Change the current layer to the cities and towns layer
 Gisdk.RunMacro "SetLayer", "Cities & Towns"
End Sub
Private Sub GetMap_Click()
 ' Convert the town_name to upper case
 town_name = UCase(TownName.Text)
 If town_name = Null Then GoTo no_name
' Locate the county specified by the client
 Dim srch_value(1 To 1)
 srch_value(1) = town_name
 rh = Gisdk.RunMacro("LocateRecord", "Cities & Towns|", "[City Name]", srch_value, Null)
If IsNull(rh) Then GoTo no_town 'No matching record was found
' Read the name of the town located
 layer = "Cities & Towns"
 Dim fldnm(1 To 1)
 fldnm(1) = "City Name"
 info = Gisdk.RunMacro("GetRecordValues", layer, rh, fldnm)
 found_name = info(1)(2)
' Check that the name matches the name requested
 If Mid(found_name, 1, Len(town_name)) <> town_name Then GoTo no_town
' Zoom to that town
 Set scp = Gisdk.RunMacro("GetRecordScope", rh)
 scp.Width = 15.1 'miles
 scp.Height = 15.1 'miles
 Gisdk.RunMacro "SetMapScope", Null, scp
Gisdk.RunMacro "RedrawMap", Null
' Copy the map to the clipboard
 file_name = Gisdk.RunMacro("GetTempFileName", "*.jpg")
 Gisdk.RunMacro "SaveMapToImage", Null, file_name, "JPEG", Null
 ' Gisdk.RunMacro "CopyMapToClipboard", Null, Null
' Show the name of the located town in the edit text
 TownName.Text = found_name

 ' Copy the map off the clipboard
 Bitmap.Picture = LoadPicture(file_name)

 TownName.SetFocus
 Exit Sub
no_town:
 TownName.SetFocus
 MsgBox ("Town not found.")
 Exit Sub

 no_name:
 TownName.SetFocus
 MsgBox ("Please, enter a town name.")
 Exit Sub

 End Sub
Private Sub Form_Unload(Cancel As Integer)
 MapClose
 End Sub
Sub MapClose()
 Gisdk.RunMacro "CloseMap", Null
 End Sub


For more information, see...

Accessing Maptitude as a COM Object