[]
Using scripts, you can use custom code in your expressions to extend the capabilities of your report. However, for complex functions, or functions you plan to use many times in the report, you also have the facility to embed the code within the report.
The following sections take you to some scenarios where scripts can be used.
This is a simple example of a single method code block:
Public Function GetDueDate() as Date
Return DateTime.Now.AddDays(30)
End Function
This is an expression used to call the method in the code block from the control's property. For example, you can call this function in the Value property of the Textbox control:
=Code.GetDueDate()
This is a simple example of how to define custom constants and variables in your code block:
Public Dim MyVersion As String = "123.456"
Public Dim MyDoubleVersion As Double = 123.456
Public Const MyConst As String = "444"
This is an expression to use the custom constant and variable in the code block from the control's property. For example, you can get the value of a variable or a constant in the Value property of the Textbox control:
=Code.MyVersion
=Code.MyDoubleVersion
=Code.MyConst
This is a simple example of a global collection code block where the code block references the report object to access the report parameter value:
Public Function ReturnParam() As String
Return "param value = " + Report.Parameters!ReportParameter1.value.ToString()
End Function
This is an expression used to call a global collection in the code block from the control's property. For example, you can call the global collection in the Value property of the Textbox control:
=Code.ReturnParam()
Use instance-based Visual Basic .NET code in the form of a code block. You can include multiple methods in your code block, and access those methods from expressions in the control properties.
type=note
Note: In a Page Report or an RDLX Report, you can use Visual Basic.NET as the script language. However, you can use both Visual Basic.Net and C# in your script for a Section Report.
Page/RDLX reports are designed to avoid scripts. However, some situations may still require using scripts. Page/RDLX reports support Visual Basic scripts, which can be used as expressions; see the following example:
Public Function GetRandom(ByVal seed As Int32, ByVal maxValue As Int32) As Int32
Return New System.Random(seed).Next(maxValue)
End Function
Then, you should set a Textbox to a value as in the example below.
=Code.GetRandom(Fields!ID.Value, 10000)