how to determine or a file is open or not (mapbasic)

1,414 views
Skip to first unread message

Peter Hollebeek

unread,
Mar 15, 2011, 6:30:07 AM3/15/11
to MapInfo-L
Thanks for any replay

Cheers Peter

Peter Hollebeek

unread,
Mar 15, 2011, 6:33:39 AM3/15/11
to MapInfo-L
Upps found it sorry

Checks if table is open and if not [true/false] to prompt for it.
'*************************************************************
Function TableOpenCheck(ByVal sCheckTable as String, ByVal lPrompt as
Logical) as Logical
Dim nCheck As Integer
Dim sFileName AS String
TableOpenCheck = True
OnError Goto TableError
nCheck = TableInfo(sCheckTable, TAB_INFO_NROWS)
Exit Function
TableError:
TableOpenCheck = False
If lPrompt Then
sFileName = FileOpenDlg("",sCheckTable,"Tab","Open Table")
Open Table sFileName AS sCheckTable
TableOpenCheck = True
End If
Exit Function
End Function

e.j.h.polle

unread,
Mar 15, 2011, 7:55:14 AM3/15/11
to MapInfo-L
Hi Peter,


I think there are numerous examples to be found on the Net of
functions to check whether a table is open or not.

Below I will give one of these. In the example you give you force an
error (from the TableInfo function) to establish that the table is not
open. In the example below the string given is compared with the names
of all the open tables; and maybe that's more elegant :-)

Declare Function TableIsOpen
(ByVal sTabName As String)
As Logical

'*************************************************
Function TableIsOpen (
ByVal sTabName As String)
As Logical
Dim iCounter, iNumberOfTables As Integer
iNumberOfTables = NumTables()
If iNumberOfTables = 0 Then
Goto no_tables_open
End If
For iCounter = 1 to iNumberOfTables
If TableInfo(iCounter, TAB_INFO_NAME) = sTabName
Then
TableIsOpen = TRUE
Exit Function
End If
Next
no_tables_open:
TableIsOpen = FALSE
End Function
'*************************************************

Cheers,


Egge-Jan

InterRob

unread,
Mar 18, 2011, 5:35:54 AM3/18/11
to mapi...@googlegroups.com
FYI: iterating all open tables (like the example provided below) is wiser, since error handling fails (!) if your MBX was invoked through another MBX (by issueing "Run Application").

Generally, it is wise to avoid any "Run Application" calls to MBXs...

Good luck with it,
Rob

2011/3/15 e.j.h.polle <e.j.h...@gmail.com>
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

Louise Kavanagh

unread,
Jan 21, 2020, 9:09:08 AM1/21/20
to MapInfo-L
Hello!

This thread is from a long time ago.  However, I am having trouble with error handling routines and spotted the line below from Rob Marjot:

"error handling fails (!) if your MBX was invoked through another MBX (by issuing "Run Application")"

Can anyone confirm that this is the case?

I have a set of rather complicated MBXs that rely on calling other MBX using the Run Application.  The mapbasic program runs perfectly well in MapInfo v11, but I am attempting to convert to v15 when it appears to ignore the error handlers.

Any ideas?

Thanks,
Louise 

On Friday, 18 March 2011 09:35:54 UTC, Rob Marjot wrote:
FYI: iterating all open tables (like the example provided below) is wiser, since error handling fails (!) if your MBX was invoked through another MBX (by issueing "Run Application").

Generally, it is wise to avoid any "Run Application" calls to MBXs...

Good luck with it,
Rob

2011/3/15 e.j.h.polle <e.j....@gmail.com>
Reply all
Reply to author
Forward
0 new messages