Have you got OpenTab declared as a function at the top of your code or in an included
Declare Function OpenTab(ByVal TableName as String, ByVal sAlias as String) As Logical
Also, you want to store (or use directly) the return value, a logical, from the function.
Dim bOpened as Logical
bOpened = OpenTab("G:\GIS_Tables\Vector_Data\Administrative\Boundaries\DSC\Boundary_DSC", "Boundary_DSC")
If Not bOpened then
' failed to open table...
Note the double quotes around the second function argument where you are passing the alias as a string. If you are passing a string literal it must be within quotations.
* EDIT *
In response to your comment, here is some code that should do the job for you. It will compile as it is, you just need to change the
myPath variable to a valid file path on your system. I have added comments so you can see what's going on.
Declare Sub Main
Declare Function OpenTab(ByVal strTablePath as String, ByVal strAlias as String) as Logical
Define ERR_INDENT Chr$(10) & Chr$(10) & Chr$(9)
Dim myAlias, myPath as String
myAlias = "test"
myPath = "..\some table path\.."
If Not OpenTab(myPath, myAlias) then '// check if OpenTab function was successful
Note "Failed to open table" & myPath & " as " & myAlias
Note "Table " & myPath & " was opened successfully as " & myAlias
Function OpenTab(ByVal strTablePath as String, ByVal strAlias as String) as Logical
Dim nTables, i as Integer
'// if path does not end in TAB file extension then append it
If Right$(strTablePath, 4) <> ".TAB" then
strTablePath = strTablePath & ".TAB"
'// check that tab file actually exists
If Not FileExists(strTablePath) then
Note "Table " & strTablePath & " does not exist."
OpenTab = FALSE
'// check if tab file is currently open, if it is then close it
nTables = NumTables()
i = nTables
While i > 0
If TableInfo(i, TAB_INFO_TABFILE) = strTablePath then
Close Table TableInfo(i, TAB_INFO_NAME)
i = i - 1
'// open tab file using the given alias. if there is an error go to error handling
OnError GoTo CaughtEx
Open Table strTablePath as strAlias
OpenTab = TRUE
'// error handling
Note "Error while attempting to open table " & strTablePath & ":" & ERR_INDENT & Error$()
OpenTab = FALSE