ActiveReports for .NET 3 Online Help Request technical support
Add Code to Script
See Also
User Guide > How-To Section > Scripting > Add Code to Script

Glossary Item Box

Use the AddCode method to inject code into the script.

The AddCode method allows actual code segments to be added to the script at run time. This is useful for allowing secure information, such as a database connection string or SQL query string, to be used inside the script without having to save it into the RPX file.

//C#
public string addThisCode() 
{ 
   string sCode = "public string ShowACMessage()"{return \"my Added Code\";}"; 
   return sCode; 
} 
private void rptAddCode_ReportStart(object sender, System.EventArgs eArgs) 
{ 
   this.AddCode(addThisCode()); 
}

'Visual Basic
Public Function addThisCode() As String 
   Dim sCode As String = "Public Function ShowACMessage() As String" _
    + Environment.NewLine + "ShowACMessage = ""my Added Code""" _
    + Environment.NewLine + "End Function"
   addThisCode = sCode 
End Function 

Private Sub rptAddCode_ReportStart(ByVal sender As Object, ByVal e As System.EventArgs) _ 
    Handles MyBase.ReportStart 
      Me.AddCode(addThisCode()) 
End Sub 

//C# Script
public void detail_Format() 
{ 
  ((TextBox)rpt.Sections["detail"].Controls["textBox1"]).Text = ShowACMessage(); 
} 

'VB.NET Script
Public Sub Detail1_Format()
   CType(rpt.Sections("Detail1").Controls("TextBox1"), TextBox).Text = ShowACMessage()
End Sub

See Also

Concepts
Scripting

©2009. All Rights Reserved.