Using VSView Reporting Edition > VBScript Expressions > Objects and Variables |
Data Field Names
Names of fields in the report's source recordset are evaluated and return the current field value. If a field name contains spaces or periods, it must be enclosed in square brackets. For example:
Example Title |
Copy Code
|
---|---|
OrderID [Customer.FirstName] [Name With Spaces] |
Report Field Names
Names of Field objects are evaluated and return a reference to the object, so you can access the field's properties). The default property for the Field object is Value, so by itself the field name returns the field's current value. For example:
Example Title |
Copy Code
|
---|---|
MyField.BackColor = RGB(200,250,100)
MyField.Font.Size = 14
MyField * 2 ' (same as MyField.Value * 2)
|
NOTE: if you give a report field the same name as a data field, you will not be able to access the report field. |
Report Section Names
Names of Section objects are evaluated and return a reference to the object, so you can access the section's properties. The default property for the Section object is Name. For example:
Example Title |
Copy Code
|
---|---|
If Page = 1 Then [Page Footer].Visible = False |
Report Object
Returns a reference to the control object, so you can access the full VSReport8 object model from your scripts and expressions. For example:
Example Title |
Copy Code
|
---|---|
"Fields: " & Report.Fields.Count
|
Page Variable
Returns or sets the value of the Page property. This property is initialized by the control when it starts rendering a report, and is incremented at each page break. You may reset it using code. For example:
Example Title |
Copy Code
|
---|---|
If Country <> LastCountry Then Page = 1 LastCountry = Country |
Pages Variable
Returns a token that gets replaced with the total page count when the report finishes rendering. This is a read-only property that is typically used in page header or footer fields. For example:
Example Title |
Copy Code
|
---|---|
"Page " & Page & " of " Pages |
Cancel
Set to True to cancel the report rendering process. For example:
Example Title |
Copy Code
|
---|---|
If Page > 100 Then Cancel = True |
Compatibility Functions
To increase compatibility with code written in Visual Basic and Microsoft Access (VBA), VSReport8 exposes two functions that are not available in VBScript: IIf and Format.
IIf evaluates a Boolean expression and returns one of two values depending on the result. For example:
Example Title |
Copy Code
|
---|---|
IIf(SalesAmount > 1000, "Yes", "No") |
Format converts a value into a string formatted according to instructions contained in a format expression. The value may be a number, date, time, Boolean, or string. The format is a string built using syntax similar to the format string used in Visual Basic or VBA.
The table below describes the syntax used for the format string:
Value Type |
Format String |
Description |
---|---|---|
Number |
Percent, % |
Formats a number as a percentage, with zero or two decimal places. For example: |
|
#,###.##0 |
Formats a number using a mask. The following symbols are recognized: |
Currency |
Currency, $ |
Formats a number as a currency value. For example: |
Boolean |
Yes/No |
Returns "Yes" or "No". |
Date |
Long Date |
Format(#12/5/1#, "long date") = "December 5, 2001" |
|
Short Date |
Format(#12/5/1#, "short date") = "12/5/2001" |
|
Medium Date |
Format(#12/5/1#, "medium date") = "05-Dec-01" |
|
q,m,d,w,yyyy |
Returns a date part (quarter, month, day of the month, week of the year, year. For example: |
String |
@@-@@/@@ |
Formats a string using a mask. The "@" character is a placeholder for a single character (or for the whole value string if there is a single "@"). Other characters are interpreted as literals. For example: |
|
@;Missing |
Uses the format string on the left of the semi-colon if the value is not null or an empty string, otherwise returns the part on the right of the semi-colon. For example: |
NOTE: VBScript has its own built-in formatting functions (FormatNumber, FormatCurrency, FormatPercent, FormatDateTime, etc). You may use them instead of the VBA-style Format function described here, if you prefer. |
Aggregate Functions
Aggregate functions are used to summarize data over the group being rendered. When used in a report header field, these expressions return aggregates over the entire recordset. When used in group headers or footers, they return the aggregate for the group.
All VSReport8 aggregate functions take two arguments:
A string containing a VBScript expression to be aggregated over the group.
An optional string containing a VBScript expression used as a filter (domain aggregate). The filter expression is evaluated before each value is aggregated. If the filter returns False, the value is skipped and is not included in the aggregate result.
VSReport8 defines the following aggregate functions:
Function |
Description |
---|---|
Avg |
Average value of the expression within the current group. For example, the expressions below calculate the average sales for the whole group and the average sales for a certain type of product: Avg(SalesAmount) |
Sum |
Sum of all values in the group. |
Count |
Count of records in the group with non-null values. Use an asterisk for the expression to include all records. For example, the expressions below count the number of employees with valid (non-null) addresses and the total number of employees: Count(Employees.Address) |
Min, Max |
Minimum and maximum values for the expression. For example: "Min Sale = " & Max(SaleAmount) |
StDev, Var |
Standard deviation and variance of the expression in the current group. These values are calculated using the sample (n-1) formulas, as in SQL and Microsoft Excel. |
StDevP, VarP |
Standard deviation and variance of the expression in the current group. These values are calculated using the population (n) formulas, as in SQL and Microsoft Excel. |
The next section explains how to use aggregate functions in detail, including how they work in the context of a report and how to use them efficiently.