Purpose
Calls a function or subroutine in a specified mbx. This works from a compiled mbx, or from Pro in a label expression, smart text, or sql select expression or in the mapbasic window. This exposes the ability to call a function or subroutine in a loaded mbx/addin. You can call this function from the MapBasic window in MapInfo Pro.
Return Value
Whatever the function being called returns in the return value of this function.
Syntax
dim result = Exec(mbxname as string, mbxfunction as string, params...)
mbxname - string. the name of the mbx to call ex: "myaddin.mbx" the mbx must be loaded. (to keep loaded it must have a handler such as an endhandler). mbxname can be empty string and we look for function in all MBX til we find one or return an error function name is required and if function is not found an error is returned. It can also call mapbasic subroutines. It can not call declared external dll functions or declared .net methods directly (wrap these in a mb function or sub) any parameters that the function requires should be passed as variable parameters after the function name, can also be none. The types should match what the function being called expects.
mbxfunction - string. the name of the mapbasic subroutine or function to call.
params... this function takes a variable number of parameters. After the first two parameters the rest are passed on to the function or subroutine being called. The number and type of the parameters must be compatible.
Example
print Exec("myaddin.mbx", "MySum4", 1,2,3,4)
Function MySum4(ByVal p1 as integer, byval p2 as integer, byval p3 as integer, byval p4 as integer) As integer
MySum4= p1 + p2 + p3 + p4
End Function
Function can also be used in a SQL statement. If user has a function within a MapBasic tool that returns a string or numeric value, etc., they can call the Exec() function within a SQL statement to update a temporary column in a table with that returned value or string. This simple example calls the AddIn_Description() function within DriveTime.MBX that takes no input parameters and returns a string, that is added as a temporary column named "ExecCol" to the query table.
select capital, state, Str$(exec("drivetime.mbx", "AddIn_Description")) "ExecCol" from usa_caps
The Exec() function can return any type, so it is really up to the user to determine what variable type should be returned from Exec function and wrap it with the appropriate conversion function like Str$() or Val(). In example above the result from Exec() is converted to a string using Str$() function. If this Str$() conversion function is not used, and the resultant query table is committed, a user will be informed that one or more of the fields in this query table are of an indeterminate type and will be saved as Char(254) but you may choose to override this default. After hitting OK, the user will be presented with a Set Field Properties dialog to set the Field type for this expression column (e.g.: ExecCol) to be saved to this new table.