Be sure to read the chapter in the MapBasic manual on Integrated Mapping,
and also look at the samples that are installed under the MapBasic folder.

In our case, we have many functions in the MBX and we want to be able to
call them individually. The way we're doing it is to create a menu in the
MBX.  It need not be hooked up to anything.  Give it an ID.  For example:

Create Menu "ModelBuilding" as
        "Set Globals for Test" ID 5000 calling SetGlobals,
        "Build mdl_Links using text trace" ID 5001 calling BuildMDL_Links,
        "Build model tables" ID 5002 calling CreateModelTables,
        "Get Model Nodes" ID 5003 calling GetNodes

In your Visual Basic, you issue a command similar to:

    '   create the empty MI tables
    MICmd = "Run Menu Command ID 5002"
    mMIInstance.Do MICmd
    
    '   extract the links...
    MICmd = "Run Menu Command ID 5001"
    mMIInstance.Do MICmd

the variable mMIInstance is of type object that was set up with:

        Set mMIInstance = CreateObject("MapInfo.Application")
        mMIInstance.Visible = False

If all your code in the MBX is in the MAIN() sub, and all you want to do is
call it, do the following:

        mMIInstance.Do "Run Application ""c:\projects\bes
emgaats\workbench\exe\EMGWorkbench.MBX"" "

The latter is what we do to load the MBX.  The MAIN routine we have creates
the menus that we later call, as above.

To "Pass parameters" to our functions, we use global variables (I know, I
know...) to pass data from Visual Basic to the MapBasic routines.  From VB,
for example...

Public Sub BuildNodes()
Dim MICmd As String
Dim WhatString As String
Dim globinfo As Object
Dim EMGRoot As String

' Look at the globals used by the first
' running MapBasic app:
Set globinfo = mMIInstance.MBApplications("EMGWorkbench").MBGlobals

    EMGRoot = "C:\projects\BES Emgaats\"
' Assign a new value to the global:
    globinfo("gmstLinksPath") = EMGRoot & "AGMaster\links\mst_links_ac.tab"
    globinfo("gmstNodesPath") = EMGRoot & "AGMaster\nodes\mst_nodes_ac.tab"
    globinfo("gmstNodeDiversionsPath") = EMGRoot &
"AGMaster\nodes\mst_node_diversions_ac.tab"
    globinfo("gmdlTracePath") = EMGRoot &
"Workbench\ProjectData\mdl_trace.txt"
    globinfo("gmdlRootFolder") = EMGRoot & "Workbench\ProjectData\TestModel"
    globinfo("gmdlLinksPath") = EMGRoot &
"Workbench\ProjectData\TestModel\Links\mdl_links_ac.tab"
    globinfo("gmdlTimeFrame") = "C"

    
    '   extract the nodes...
    MICmd = "Run Menu Command ID 5003"
    mMIInstance.Do MICmd

End Sub

=========================================
There have been some suggestions on better ways to do the "parameter
passing", but we've not investigated them yet.

Hope this helps.



_______________________________________________________________________
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, send e-mail to [EMAIL PROTECTED] and
put "unsubscribe MapInfo-L" in the message body.

Reply via email to