Find Zip

Preview:

DESCRIPTION

vbmapinfomap

Citation preview

Option ExplicitDim mapinfo As ObjectDim mapid As LongDim legendid As LongPrivate Sub DoLegendMaintence() 'This routine is responsible for showing/hiding the legend 'associated with the thematic map Dim bHasThematic As Integer Dim ndx, count As Integer bHasThematic = False count = Val(mapinfo.Eval("MapperInfo(" & mapid & ",9)")) For ndx = 1 To count If (Val(mapinfo.Eval("LayerInfo(" & mapid & "," & ndx & ",24)")) = 3) Then bHasThematic = True Exit For End If Next If (bHasThematic And legendid = 0) Then 'create legend mapinfo.do "Set Next Document Parent WindowInfo(" & mapid & ",12) Style 1" mapinfo.do "Create Legend From Window " & mapid legendid = Val(mapinfo.Eval("WindowID(0)")) ElseIf (Not bHasThematic And legendid 0) Then 'destroy legend mapinfo.do "Close Window " & legendid legendid = 0 End IfEnd SubPrivate Sub Form_LinkExecute(CmdStr As String, Cancel As Integer) ReDim args(8) As String Dim start, pos, ndx, length As Integer If (Left$(CmdStr, 3) "MI:") Then MsgBox "Unexpected LinkExecute: " & CmdStr Exit Sub End If args(8) = "" 'make sure we initialize this for later test ndx = 1 start = 4 length = Len(CmdStr) While (start < length) pos = InStr(start, CmdStr, ",") If (pos = 0) Then args(ndx) = Mid$(CmdStr, start, 32767) start = length Else args(ndx) = Mid$(CmdStr, start, pos - start) start = pos + 1 End If ndx = ndx + 1 Wend If (args(8) "") Then 'CommandInfo(8) is the ID of the menu item we clicked 'We use as the ID value the MapInfo menu command number 'that we want to run when we get this event mapinfo.RunMenuCommand Val(args(8)) Call DoLegendMaintence Else 'Must have been tool callback MsgBox "You clicked at ( " & args(1) & " , " & args(2) & " )" End IfEnd SubPrivate Sub Form_Load()Dim bUnableToCreateObj As IntegerDim strfile As String ' This code demonstrates how to structure an app that can be run ' with either MI Pro, or a MI Pro runtime as the OLE server. Be sure ' to see the code below that creates a custom button using different ' approaches based on whether or not a runtime is in use. bUnableToCreateObj = False On Error GoTo cant_createApplicationObject Set mapinfo = CreateObject("MapInfo.Application") On Error GoTo 0 If bUnableToCreateObj Then On Error GoTo cant_createRuntimeObject Set mapinfo = CreateObject("MapInfo.Runtime") On Error GoTo 0 End If 'indicate that we don't have a legend window legendid = 0 'Initialize the application mapinfo.do "Set Application Window " & FindZipForm.hWnd strfile = mapinfo.Eval("programdirectory$()") mapinfo.do "open table " & """" + strfile + "D:\Users\vbPictureMI\.mapbasic.v7.0.build.8\SAMPLES\VB6\FINDZIP\Data\Tut_data\Tut_usa\usa\STATES.TAB" + """" + " Readonly Interactive" mapinfo.do "Open Table " & """" + strfile + "DATA\Tut_Data\Tut_Usa\USA\US_ZIPS.TAB" + """" + " ReadOnly Interactive" 'Disable the help subsystem - we don't support help in this application mapinfo.do "Set Window Help Off" 'Disable the control in the Layer Control dialog box mapinfo.do "Alter MapinfoDialog 1800 Control 12 Disable" 'Make the Info tool parented to our form for when ' the user uses that tool mapinfo.do "Set Window Info Parent " & FindZipForm.hWnd mapinfo.do "Set Window Info ReadOnly" 'Reprogram the map's shortcut menu (right-click on map) ' note well that we reprogram the Layer Control & Create Thematic ' to call us back via DDE so that we can do maintenence after these run mapinfo.do "Create Menu ""MapperShortcut"" ID 17 as ""&Layer Control..."" ID 801 calling DDE ""FindZip"",""MainForm"",""Create &Thematic Map..."" ID 307 calling DDE ""FindZip"",""MainForm"",""View &Entire Layer..."" calling 807" 'Create our custom "Query" tool ' The positive case is true if the runtime is acting ' as the OLE server If mapinfo.Eval("SystemInfo(4)") = "T" Then mapinfo.do "Create ButtonPad ID 3 As ToolButton Calling DDE ""FindZip"",""MainForm"" Cursor 128 DrawMode 34 ID 101" Else mapinfo.do "Alter ButtonPad ID 3 Add ToolButton Calling DDE ""FindZip"",""MainForm"" Cursor 128 DrawMode 34 ID 101" End If 'Create the Map window mapinfo.do "Set Next Document Parent " & MapFrame.hWnd & " Style 1" mapinfo.do "Map From States" mapid = Val(mapinfo.Eval("WindowID(0)")) mapinfo.do "Set Map Window " & mapid & " Center (-95.5,36.5) Zoom 3300" 'Select the grabber tool as the active tool, mapinfo.RunMenuCommand 1702 Exit Subcant_createApplicationObject: ' If we can't create the object using MapInfo Pro, we try to use the runtime bUnableToCreateObj = True Resume Nextcant_createRuntimeObject: ' If the attempt to create the runtime object also fails, ' we are done. MsgBox "Unable to CreateObject of MapInfo.Application" End End SubPrivate Sub Grabber_Click() mapinfo.RunMenuCommand 1702End SubPrivate Sub InfoTool_Click() mapinfo.RunMenuCommand 1707End SubPrivate Sub Menu_CreateThematic_Click() mapinfo.RunMenuCommand 307 Call DoLegendMaintenceEnd SubPrivate Sub Menu_Exit_Click() End 'ProgramEnd SubPrivate Sub Menu_LayerControl_Click() mapinfo.RunMenuCommand 801 Call DoLegendMaintenceEnd SubPrivate Sub Menu_PrintForm_Click() 'Update picture on the form mapinfo.do "Save Window " & mapid & " As ""C:\MAP.WMF"" Type ""WMF""" MapFrame.Picture = LoadPicture("C:\MAP.WMF") 'Now, print the form PrintForm Kill "C:\MAP.WMF"End SubPrivate Sub Menu_PrintMap_Click() mapinfo.do "PrintWin"End SubPrivate Sub Menu_ViewEntire_Click() mapinfo.RunMenuCommand 807End SubPrivate Sub Picture1_Click()mapinfo.RunMenuCommand 1705End SubPrivate Sub Query_Click() mapinfo.do "Run Menu Command ID 101"End SubPrivate Sub ZipCode_Change() If (Len(ZipCode.Text) = 5) Then mapinfo.do "Find Using US_ZIPS(Zip)" mapinfo.do "Find """ & ZipCode.Text & """" If (Val(mapinfo.Eval("CommandInfo(3)")) >= 1) Then mapinfo.do "Set Map Window " & mapid & " Center(CommandInfo(1), CommandInfo(2)) Zoom 500" End If End IfEnd SubPrivate Sub ZoomIn_Click() mapinfo.RunMenuCommand 1705End SubPrivate Sub ZoomOut_Click() mapinfo.RunMenuCommand 1706End Sub

Recommended