ActiveReports3 Request technical support
Script Property
See Also  Example


Sets or returns the script code for a report's events.  Either this property or the script editor may be used to add script to a report.

Syntax

Visual Basic (Declaration) 
Public Property Script As String
Visual Basic (Usage)Copy Code
Dim instance As ActiveReport3
Dim value As String
 
instance.Script = value
 
value = instance.Script
C# 
public string Script {get; set;}

Return Value

The current script code. The default value is an empty string.

Example

This snippet assumes that you have html in the RichTextBox, and that the Modifiers property of the RichTextBox is set to Public.
C#Copy Code
Private void btnScript_Click(object sender, System.EventArgs e)
{
   
string sScript = string.Empty;
   rptDataDynamics rpt = New rptDataDynamics();

   sScript +=
"public void ReportHeader_Format()";
   sScript +=
"{";
   sScript +=
"rpt.RichTextBox1.Html = rpt.RichTextBox1.Text;";
   sScript +=
"}";

   rpt.Script = rpt.Script +
"\n" + sScript;
   rpt.Run();
   arv.Document = rpt.Document;
}
Visual BasicCopy Code
Private Sub btnScript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScript.Click
    Dim sScript As String = String.Empty
    Dim rpt As New rptDD

    sScript = "public void ReportHeader_Format()"
    sScript = sScript + "{"
    sScript = sScript + "rpt.RichTextBox1.Html = rpt.RichTextBox1.Text;"
    sScript = sScript + "}"

    rpt.Script = sScript
    rpt.Run()
    Viewer1.Document = rpt.Document
End Sub

Remarks

The Script property can be used to make modifications to the report outside the code written in the report's events. The script events run immediately after their matching ActiveReports code-behind events and take precedence over the code inside the project.

If reports with scripts are saved to XML, the scripts (unlike code-behind) are incorporated into the XML file. Changes can be made to the XML file scripts and then loaded back into a report project to show the changes. This allows reports to be modified without requiring the project to be recompiled.

When referencing the report in the script, use rpt instead of the report's name or "Me" or "this".

In order to reference a member of the report class using the "rpt" named object, the member has to be a public member. You can use a control's modifier property to change the generated code for a control from private to public.

If you plan to run the report from a stand-alone RPX file without the compiled code-behind class, your scripting code would have to reference the report class controls using the Controls collection instead of by name.

Scripts are compiled at run time using the language specified in the ScriptLanguage property.

See Also