Home - Accesskey: 1
TransTOOLs: Technical Notes

MultiBase: Technical notes of version 2.0 release 05

5. Functions

5.1. addtoclist(rowid)

Add the row rowid to the current list of the form table.

5.2. chdir(expr)

Changes to directory expr.

5.3. closedir()

Closes the current open directory (see also opendir).

5.4. cursorpos(on_off, line, col)

[UNIX/DOS]: Permits switching of cursor display depending on its screen position.

5.5. dokey(expr)

Simulates pressing of a key, writing its value to the key buffer.

Example:

call dokey("fleft")
call dokey(3) -> Control-C.
call dokey(13) -> RETURN.
call dokey("freturn") -> RETURN.
call dokey("309-4589A") -> String.

5.6. endquery()

Displays the number of rows of the current list of the FORM's active table and positions to the first row.

5.7. evalarray(array,number)

This function equals «evalvar» but works with an array element. The element is identified by «number».

5.8. evalcond(exp1, oper, exp2, exprtrue, exprfalse)

Compares "exp1" with "exp2" using operator "oper" and returns:

"oper" can be one of the following: "=", ">", "<", ">=", "<=", "!=", "<>", "like", "matches"

Example:

let a = evalcond(b, ">", c, "ddd", a)

if equivalent to:

if b > c then
    let a = "ddd"
else
    let a = a

5.9. evalfun(funname [,arg1, ..., argn])

Executes function "funname" and - if it exists - returns its value.

Example:

evalfun("getctlvalue", "version") -> getctlvalue("version")
evalfun(fun_name(), parm1) -> If function fun_name() returns"fun1" this equals -> fun1(parm1)

5.10. evallnull(exp1, exprtrue, exprfalse)

Evaluates if "exp1" is a NULL value or not. Returns:

Example:

pause evalnull(payform, "no valid payform", "payform is: " & payform)

5.11. evalvar(expr)

Evaluates a variable's contents. The variable name is given in "expr" to the function. The function will then return the value.

5.12. fgetquery(where_clause [, collist])

This function is similar to the statement GET QUERY WHERE....

Parameter Description
where_clause Alphanumerical expression containing a WHERE and/or ORDER BY condition for the QUERY.
collist Alphanumerical expression with a list of comma separated column names. They will be added to the SELECT of the QUERY. If an ORDER BY is used in the where_clause the columns used in the ORDER BY must be specified in collist, because otherwise the SQL will display an error like: "SELECT list must include column (...) for ORDER BY".

The number of rows found will be returned.

Example:

let num = fgetquery("order by client", "client")
let num = fgetquery("where client = 1")
let num = fgetquery("where client > 2 order by client", "client")

Also the following parameters may be passed in special cases:

fgetquery(fquery(TRUE))

5.13. filesize(file)

Returns the size of the file "file" in bytes. If the file is not existent or if the parameter is invalid NULL will be returned.

Example:

if filesize("file")>0 then
...

5.14. fquery()

The function fquery() equals the QUERY statement, but with the difference that this function will only return the corresponding SELECT condition.

Example:

let a = fquery() -> i.e. the value of "a" might be: "where customer > 1"
...

5.15. getctlvalue(expr)

Returns various CTL system information. What is being returned depends on the parameter "expr".

expr Return value
"version" CTL version (i.e. "2.0.05")
"O.S." Returns Operating System (z.B. "WINDOWS")
"porting" Returns OS variant (i.e. "AIX")
"atcol" Screen column at which CTL was started.
"atrow" Screen row at which CTL module was started.
"ctlname" Name of the current CTL module.

5.16. getcwd()

Returns the name of the current work directory.

5.17. gotoclist(expr)

With this function you can position to a specific row within a FORM's current list. The meaning of "expr" is:

expression = 0 Positions to the current row (no change).
expression = n Positions to the n-th. row.
expression = -1 Positions to the last row.
expression = -2 Positions to the last but one row.
...  

5.18. gotoscreen(expr)

Permits to choose the page («SCREEN») in a FORM/FRAME with "expr". Possible values are:

expression = 0 Positions to the current page.
expression = n Positions to page «n».
expression = -1 Positions to the last page.
expression = -2 Positions to the last but one page.
...  

5.19. keypressed()

Returns TRUE if a character is contained in the keyboard buffer, FALSE in the other case. If TRUE is returned the key stored in the buffer can be read by a READ KEY or PAUSE statement or it may be used by any CTL element.

Example:

{Clear keyboard buffer}
while keypressed()=true
read key

5.20. letarray(expression, number, value)

Equals letvar but the value will be assigned to the array element indicated in «number».

5.21. letvar(expression, value)

The functions assigns the value "value" to the program variable passed to it in "expression".

5.22. licence()

Returns the licence number of the CTL.

5.23. nocomment(source, dest)

Copies the contents of the file "source" to the file "dest" eleminating any comment lines (those beginning with ‘#’). The function returns:

Example:

nocomment("fl.err", "fl.sct")

5.24. msgtext(msg [, value])

The function msgtext now allows to pass a value as second parameter, which will be inserted in the message when required.

Example:

msgtext (150, "items")
    - Message 150 = "Table %s does not exist in database" returns:
    "Table items does not exist in database".

It is only possible to pass one or none value. In the first case the must be include a %s.

5.25. opendir(path)

This function opens a directory. Returns TRUE if directory exists and can be opened, FALSE in the other case. Only one directory can be open at a time. In case of executing two ‘opendir’ functions the second one automatically executes a ‘closedir’ on the first directory opened.

Example:

if opendir(dir)=true then begin
  forever begin
    let fil = readdir()
    if fil is null then break
    ...
    ...
  end
  call closedir()
end

5.26. putenv(var, value [, mode])

Adds the environment variable "var" to the current user environment and assigns it the value "value". The optional parameter "mode" is used to indicate if the new environment variable is to be made known also to the running CTSQL.

Mode Description
0 Value is only valid for CTL (resp. CTSQL if it is of its own variables).
1 Value is only for CTSQL.
2 Value is for CTL and CTSQL.

Please check page A/10 in the MultiBase Reference Manual for further information.

5.27. readdir()

Reads a filename from an open directory (see also opendir).

5.28. sqlclose(handle)

Closes the cursor handle (see also sqlselect).

5.29. sqldescribe(select_instr [,flag][, char_separator])

This function returns a string with all column names, types and optionally database defined attributes from a SELECT statement passed to it.

flag flag = 0: Attributes are not considered (Default).
flag = 1: Attributes are considered.
char_separator Separator between the columns in the list. By default commas (,) are used.

Example:

tsql "create table t1 (" & sqldescribe("select * from customers") & ")"

5.30. sqlfetch(handle)

Reads the next row and returns its contents in UNLOAD format. If the end of cursor is reached NULL is returned. (see also sqlselect).

5.31. sqlreset([flag])

Flag Description
0 (Default) All cursors of a module are closed. This is true for FORMs and WINDOWs and for the cursors defined by the user (DECLARE CURSOR).
1 Only the Cursors of the FORM are closed.

5.32. sqlselect(select_str)

Uses "select_str" to open a Cursor and returns a handle (>=0). With this handle the cursor will be identified in sqlfetch and sqlclose. If an error occurs NULL is returned.

Example:

let handle = sql_select("select " && selected_cols() && " from items")
let a = sqlfetch(handle)
call sqlclose(handle)

This example uses a user-defined function selected_cols which returns the columns to be selected in a char.

5.33. strcount(where, what)

Counts the appearance of "what" in "where". Returns the number of appearances or NULL in case of parameter error.

Example:

let num = strcount("A-3393457332", "33")

5.34. strgetword(where, charseparator [,num [, typesep]])

Returns the n-th. word in the string "where".

Parameter Description
where String to be searched.
num Number of word within string. If "num" is ommitted the first word will be returned.
charseparator Separator.
typesep If its value is FALSE this indicates that various separators are equivalent to one separator. If every separator shall be treated separately TRUE is to be used. If charseparator is a space the default value is FALSE else TRUE.

The function returns NULL if

The number of words should be checked before with strnumwords.

Example:

let a = strgetword("/tmp::/usr", ":", 2, false)

In this case the returned value is "/usr".

5.35. strlocate(where, what [, num])

Searches one string in another.

Parameter Description
where String to be searched.
what String to be found.
num Searches the num-th. occurance of "what" within "where" (default 1). If "num" is passed as a negative the num-th. search will start at the end of string (reverse).

In case of parameter error NULL will be returned.

5.36. strltrim(expr)

Eleminates spaces (blank) to the left of string "expr" and returns the result without leading spaces. If parameter error, NULL will be returned.

5.37. strnumwords(where, charseparator [, typesep])

Counts the number of words in a string. Parameters are compatible to strgetword. In case of parameter error NULL is returned.

Example:

let oldpath = "/path1:/path2:/path3"
let num = strnumwords(oldpath, ":")
for i = num down to 1
let newpath = newpath & strgetword(oldpath, ":", i) & ":"

5.38. strrepeat(expr, num)

Repeats expr num times. The maximum length of the returned string is 512 characters.

Example:

let a = strrepeat("-.", 40)

5.39. strreplace(where, charold, charnew [,num])

Replaces a substring with another substring within a source string.

Parameter Description
where String to be modified.
charold String to be replaced.
charnew Replacement.
num Number of replacements to be done. If num is not indicated all occurances of charold will be replaced by charnew.

The result will be the modified string. charold and charnew may be of different length only if the string size is below 512 characters. If charnew is an empty string charold will be cleared.

If a parameter error occurs NULL is returned.

Example:

let var = strreplace("/disk1/demo", "k1", "k2", 1)

5.40. strrtrim(expr)

Eleminates spaces (blank) to right of the string passed as "expr" and returns the new string (without padding chars). If a parameter error occurs NULL is returned.

5.41. strtrim(expr)

Eleminates leading and padding spaces (blanks) of "expr". Also duplicated spaces between tokens are compressed into a single space. NULL is returned in case of an error.

5.42. testfile(file, attr)

Checks whether a file exists or if it is of the type/has permissions as indicated.

Parameter Description
file File
attr

Expression identifying permissions. Every character stands for one permission.
‘r’: Read Permission.
‘w’: Write Permission
‘x’: eXecute Permission.
‘f’: Type is a FILE.
‘d’: Type is a DIRECTORY.

Attributes can be freely combined.

The function returns TRUE if all of the attributes indicated match. FALSE will be returned if one or more attributes don't mach or the file/directory is not existent.

When an erroneous parameter is passed the function will return NULL.

Example:

if testfile("file", "rwf")=TRUE then
....

5.43. yes(expr [,def])

A second parameter can be passed to determine the default option. Valid are "y" and "n" for the options YES/NO, while "n" will be used as default (when the parameter is ommitted).

« »