Title: Re: [MI-L] Integrated mapping with Visual Basic

Chris,

Here is some code I wrote using VBA in Access to grab the county name based on the centroid of the mapper window. Hope this helps:

(The sCounty etc. variables are dimmed in a module to make them public)


Public Function Extract_Names(CntyTab, CntyCol, ProsTab, ProsCol, TRSTab, TRSCol, OthrTab, OthrCol As String)

'POPULATE COUNTY,PROSPECT,TR/SURVEY,OTHER VARIABLES FROM UNDER CENTROID OF MAP WINDOW. USE IN TITLE FOR LAYOUT.

'USAGE: extract_names "ca_county", "name", roc_prospects", "name", "none", "none" - use "none" to ignore

'miobj.Do "set event processing off"

Dim xCoord, yCoord, TabName As String

Dim i, i_Found, i_rowID As Integer

sCounty = ""

sProspect = ""

sSurvey = ""

sBoundary = ""

If CntyTab <> "none" Then

    Map_Layer_Selectable CntyTab, "on"

End If

If ProsTab <> "none" Then

    Map_Layer_Selectable ProsTab, "on"

End If

If TRSTab <> "none" Then

    Map_Layer_Selectable TRSTab, "on"

End If

If OthrTab <> "none" Then

    Map_Layer_Selectable OthrTab, "on"

End If

Debug.Print " layers on"

xCoord = miobj.Eval("mapperinfo(" & MasterMapID & ",3)")

yCoord = miobj.Eval("mapperinfo(" & MasterMapID & ",4)")

msg = "searchpoint(" & MasterMapID & "," & xCoord & "," & yCoord & ")"

i_Found = miobj.Eval(msg)

For i = 1 To i_Found

  TabName = miobj.Eval("searchinfo(" & i & ", 1)")

    Select Case TabName

        Case CntyTab

            i_rowID = miobj.Eval("searchinfo(" & i & ", 2)")

            miobj.Do ("fetch rec " & i_rowID & " from " & CntyTab)

            sCounty = miobj.Eval(CntyTab & "." & CntyCol)

        Case ProsTab

            i_rowID = miobj.Eval("searchinfo(" & i & ", 2)")

            miobj.Do ("fetch rec " & i_rowID & " from " & ProsTab)

            sProspect = miobj.Eval(ProsTab & "." & ProsCol)

        Case TRSTab

            i_rowID = miobj.Eval("searchinfo(" & i & ", 2)")

            miobj.Do ("fetch rec " & i_rowID & " from " & TRSTab)

            sSurvey = miobj.Eval(TRSTab & "." & TRSCol)

        Case OthrTab

            i_rowID = miobj.Eval("searchinfo(" & i & ", 2)")

            miobj.Do ("fetch rec " & i_rowID & " from " & OthrTab)

            sBoundary = miobj.Eval(OthrTab & "." & OthrCol)

        Case Else

            Debug.Print "case else " & TabName

    End Select

Next

'MsgBox sCounty & " / " & sProspect & " / " & sSurvey & " / " & sBoundary

    Map_Layer_Selectable CntyTab, "off"

    Map_Layer_Selectable ProsTab, "off"

    Map_Layer_Selectable TRSTab, "off"

    Map_Layer_Selectable OthrTab, "off"


End Function

Public Function Map_Layer_Selectable(ByRef sTable, On_Off As String)

'MAKE A MAP LAYER SELECTABLE IF NO AND VISAVERSA. IF IS ALREADY IN DESIRED STATE = DO NOTHING.

Dim msg, sLayerNum As String

sLayerNum = Get_Layer_nmbr(sTable)

If Then

    msg = "layerinfo( " & MapID & ", " & sLayerNum & ", 3)"

    If miobj.Eval(msg) = "F" Then 'IS SELECTABLE OFF?

        miobj.Do ("set map layer " & sTable & " selectable on") 'MAKE SELECTABLE

    End If

Else 'If Then

    If miobj.Eval("layerinfo( " & MapID & ", " & sLayerNum & ", 3)") = "T" Then 'IS SELECTABLE On?

    Debug.Print " sel2 " '& miobj.Eval(msg)

        miobj.Do ("set map layer " & sTable & " selectable off") 'MAKE SELECTABLE

        Debug.Print " sel2-off "

    End If

End If

'Debug.Print " selectable " & sTable

End Function

Public Function Get_Layer_nmbr(ByVal strLayerName As String) As Integer

'GET LAYER NUMBER BY PASSING THE LAYER NAME

Dim i As Integer

For i = 1 To miobj.Eval("mapperinfo( " & MapID & ", 9)")

'Debug.Print " layer num " & i

    If miobj.Eval("layerinfo( " & MapID & ", " & i & ", 1)") = strLayerName Then

        Get_Layer_nmbr = i

        Exit Function

    End If

Next

Get_Layer_nmbr = 0

Debug.Print " layer num " & i

End Function



Original message:

Message: 6

Date: Wed, 8 Mar 2006 15:51:12 +0100

From: "Christophe Brabant" <[EMAIL PROTECTED]>

Subject: [MI-L] Integrated mapping with Visual Basic

To: <[email protected]>

Message-ID: <[EMAIL PROTECTED]>

Content-Type: text/plain; charset="us-ascii"

Hi everyone

 

Could someone show me an advanced sample VB or VC++ program, to drive Mapinfo ?

 

I already used the little example from MI Help, to display a Map into a PictureBox, create menus etc....

but I ask to myself some questions :

 

1)  how to pass advanced commands to MI with VB ? for example, a "For ....

Next" or "While ...." statement :

 

Fetch First from Selection

While Not EOT Selection

    Note ObjectInfo(Selection.Obj, OBJ_INFO_TYPE)

    Fetch Next From Selection

Next

 

The previous example can not be passed to MI into a single-line command...

 

2) How to drive the mouse position :

 

In MapBasic, the SearchPoint and SearchRectangle statements can be used through a ToolButton Could I use directly these statements from VB application when user clicks onto a Map, without ToolButton, to retrieve the map objects ?

 

I hope my questions are clear.

 

Chris

_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

Reply via email to