Xbasic

REPLACE_PARAMETERS Function

Syntax

Output_Expression as C = replace_parameters(C input_expression ,P vars )

Arguments

input_expression

An Xbasic expression.

vars

Pointer to the frame where the variables exist.

Description

Replaces the parameters in an expression. Set 'vars' to local_variables()

Discussion

REPLACE_PARAMETERS() is useful when you want to substitute parameters (i.e. variables) into an expression, such as a filter expression. Variable_Frame is a pointer to the variable frame in which the variables that are to be substituted have been defined. In most situations, Variable_Frame will be set to LOCAL_VARIABLES(). Note : LOCAL_VARIABLES()is the function that returns a pointer to the local variable frame. The parameters in the expression must be enclosed in square brackets ( [ ] ) and are preceded with varC->, varN->, varD-> or varL->, depending on the type of the variable. Note : You must use Version 6 or higher to support varT->.

For example:

Filter = "lastname = [varC->whatLastname] .and. date_of_birth > = [varD->whatDate]"

The REPLACE_PARAMETERS() function will replace the parameters in the above expression with their actual values. Assuming that whatLastname is "Smith" and that whatDate is {12/18/1952} then the expression:

replace_parameters(filter, local_variables() )

will return:

lastname = "Smith" .and. date_of_birth > = {12/18/1952}

Example

Run a report where the filter is based on parameters.

dim whatLastname as C
dim whatDate as D
whatLastname = "Smith"
whatDate = {12/18/1967}
Filter = "lastname = [varC->whatLastname] .and. " + \"date_of_birth > = [varD->whatDate]"
filter = replace_parameters(filter, local_variables() )
report.print("customer",filter)

Note : If the "whatLastname" and "whatDate" variables are DIMmed as SHARED variables, then this example can be considerably simplified because you can refer the variables directly in the filter expression, and you therefore do not need to use the REPLACE_PARAMETERS() function:

Use shared variables.

dim SHARED whatLastname as C
dim SHARED whatDate as D
whatLastname = "Smith"
whatDate = {12/18/1967}
filter = "lastname = var->whatLastname .and. date_of_birth = var->whatDate"
report.print("customer", filter)

Limitations

Desktop applications only.

See Also