Switch to: V12V11V10V9V8V7V6V5

VReport Class: Methods

VReport.RunScript()

Declaration:

RunScript( inScript as String ) as String

Parameters:

  • inScript – The code that should be executed by the JavaScript engine. This code can access the object model of the report directly (e.g. change properties of controls), without need to use intermediate parameters.

Returns the string representation of a result.

This method can be useful for initialization of the report variables and properties. To make this work, RunScript method should be called before issuing any of the printing methods of the report.

Example:

Let you have a report with a label that you need to rotate by arbitrary angle, but this need and angle value are known only at runtime. Then you can define rotation in the RunScript method.

dim theReport as VReport
 
theReport = my_project.MakeNewReport( 
               "report_1", 
               "sqlite://c:/somedb.sqlite", 
                "SELECT fldName, fldPhone FROM tblPerson" )
 
theReport.RunScript( "report.controls.label1.rotate = 30;" )

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" )