Switch to: V9V8V7V6V5

VReport Class: Methods

VReport.SetParameterValue()

Declaration:

SetParameterValue( 
    inName       as String,
    inValue      as String )

Parameters:

  • inName - The name of the parameter.
  • inValue - The value to set for parameter.

Description:

Sets the value of the given parameter.

At first parameters should be defined, there are two places, where you can do it:

  • in the source query
  • in the Expression Field control

Parameter definition has the following format:

$P( param1[=default_value1] )

The default value is optional and used only if a value wasn't provided in code.

Then you can set values for parameters using SetParameterValue from the application before printing into target format - PDF, HTML or directly to the printer.

The parameters can be used in subreports, in query and expressions, just like in the main report.

Query Parameters

Such parameters should be inserted into the source query of report, for example:

SELECT * FROM t1 WHERE f1 = $P(pId)

You can use parameters in the following places:

  • in the Query dialog of Valentina Studio Report Editor
  • in the query passed to the VProject.MakeNewReport method.

It allows to define a query once (either in Valentina Studio or in code), and use it multiple times setting different parameter values.

Examples:

Let we have a report “report_1”, with the following source query:

SELECT * FROM tblPerson WHERE fldAge >= $P(pAge)

The default value is 20.

1.

dim theReport as VReport
 
theReport = my_project.MakeNewReport( 
               "report_1", 
               "sqlite://c:/somedb.sqlite" ) 
 
theReport.SetParameterValue( "pAge", "10" )

Query text is omitted, so query stored in the project will be used. SetParameterValue changes default parameter value to show all records with fAge >= 10.

2.

dim theReport as VReport
 
theReport = my_project.MakeNewReport( 
               "report_1", 
               "sqlite://c:/somedb.sqlite" )

Query text is omitted, so query stored in the project will be used, it will return all records with fAge >= 20.

3.

dim theReport as VReport
 
theReport = my_project.MakeNewReport( 
               "report_1", 
               "sqlite://c:/somedb.sqlite",
               "SELECT * FROM tblPerson WHERE fldAge < $P(pAge)" )
 
theReport.SetParameterValue( "pAge", "30" )

Query text with parameters is defined explicitly.

Expression Parameters

Such parameters should be inserted into report using macro $P in the Expression Field control.

Example:

dim theReport as VReport
 
theReport = my_project.MakeNewReport( 
               "report_1", 
               "sqlite://c:/somedb.sqlite", 
                "SELECT fldName, fldPhone FROM tblPerson" )
 
theReport.SetParameterValue( "param1", "value1" )