View Single Post

  #3 (permalink)  
Old 02-16-2007
marmi marmi is offline
Junior Member
White Belt
 
Join Date: Feb 2007
Posts: 2
Re: Work with mapinfo by VB6, help me!!!

hi
this is a way to load a mapinfo table within a vb6 form.
create a vb6 project.

on the form place a picturebox, a commandbutton and a commondialog

// this code goes into module level//
Public itsamap As Boolean
Public mapWinID As Long
Public mapinfo As Object

public Sub OpenATable()
Dim file_name As String
Dim tabName As String
On Error GoTo userCancelled
form1.CommonDialog1.Filter = "MapInfo Tables (*.tab)|*.tab"
form1.CommonDialog1.FilterIndex = 1
form1.CommonDialog1.ShowOpen
file_name = form1.CommonDialog1.FileName
tabName = mapinfo.Eval("PathToTableName$( """ & file_name & """ )")
mapinfo.Do "Open Table """ & file_name & """ as " & tabName
mapinfo.Do "Set Table " & tabName & " ReadOnly"
If mapinfo.Eval("TableInfo(" & tabName & "," & 5 & ")") = "F" Then
MsgBox "Cannot open table!"
mapinfo.Do "Close Table " & tabName
Exit Sub
End If
If itsamap Then
mapinfo.Do "Add Map Layer " & tabName
Else
mapinfo.Do "Set Next Document Parent " & form1.picture1.hWnd & " Style 1"
mapinfo.Do "Map From " & tabName
mapWinID = CLng(mapinfo.Eval("FrontWindow()"))
itsamap = True
End If
Exit Sub
userCancelled:
Exit Sub
End Sub
-----------------------------------------------------------------------
// this code goes into form level//
Private Sub Form_Load()
Set mapinfo = CreateObject("MapInfo.Application")
mapinfo.Do "Set Application Window " & form1.hWnd
End Sub

Private Sub Command1_Click()
Call OpenATable
End Sub
Reply With Quote