Common‎ > ‎VBScript Programmer's Reference‎ > ‎Variables‎ > ‎Data Object‎ > ‎

Data object's methods for data access

GetCellValue

Returns the value for the field identified by its name.   Returns the value from the current record if Select was called.  Otherwise, the value is taken from the first record or according to the record object, if set.

Function GetCellValue( field_name )

Parameters:
string field_name - name for the field, whose value should be returned.

Return value:
variant - the requested field value.
An exception is thrown in case of errors.

VB Sample

Dim val
If DB.Select() Then
   Do
      val = DB.GetCellVaue( "Field1" )
   Loop While( DB.GoNext() )
End If

GetRecordCount

Returns the number of records in the record set. A call to this method can be time consuming, so it is not recommended for record set traversal: use the Do ... Loop While ( DB.GoNext() ) construct instead. Select is not required for this method to be called.

Function GetRecordCount()

Parameters:
none

Return value:
integer - number of records in the record set.
An exception is thrown in case of errors.

VB Sample

Dim count
count = DB.GetRecordCount()

GetRecordNumber

Returns the current record number. The range of this value is from 0 to GetRecordCount() - 1. Select must be called prior to making calls to this method.

Function GetRecordNumber()

Parameters:
none

Return value:
integer - current zero-based record number.
An exception is thrown in case of errors.

VB Script

Dim current
If DB.Select() Then
   DB.GoRandom( 25 )
   current = DB.GetRecordNumber() ' current is 25 now
End If

GetValues

Returns an array of values for the field(s) specified in the input parameter. The return value is an array of arrays if the input parameter contains multiple fields and a single array if the input parameter is a single field. This method does not need a prior call to Select method. The return values are taken from all records in the record set.

Function GetValues( field_name | array of field_names )

Parameters:
variant - string | array of strings - field's name or an array of field names.

Return value:
variant - an array of values for the field, passed in as a parameter; an array of variant arrays - if an array of field names is passed in as a parameter, each array holds field data for the respective field name.
An exception is thrown in case of errors.

VB Sample

Dim values, f1, f2, f3
DB.Scope.Set( "Field1 > 1000" )
values = DB.GetValues( Array( "Field1", "Field2", "Field3" ) )
f1 = values(0)
f2 = values(1)
f3 = values(2)
sum = f1(0) + f2(0) + f3(0) 'sum has a total value of the three field values from the first record

GetStatistics

Returns an array of aggregate values (Min,Max,Sum,Count,Avg) for the field(s) specified in the input parameter. Select is not needed for this method to operate. Scope object's setup is used for records filtering.

Function GetStatistics( name | array of names )

Parameters:
variant - string | array of strings - an aggregate function name or an array of aggregate function names.

Return value:
variant - an aggregate value for the aggregate function, which was passed in as a parameter; an array of variants - if an array of aggregate functions was passed in as a parameter, each array element holds an aggregate value for the respective aggregate function.
An exception is thrown in case of errors.

VB Sample

Dim aggregate_values, f1, f2, f3
DB.Scope.Set( "Field1 > 1000" )
aggregate_values = DB.GetStatistics( Array( "Count(Field1)", "Sum(Field2)", "Avg(Field3)" ) )

GetFieldCount

Returns the number of fields present in the record set.  Select must be called prior to making calls to this method.

Function GetFieldCount()

Parameters:
none

Return value:
integer - the number of fields in the record set.
An exception is thrown in case of errors.

VB Sample

Dim f_count
If DB.Select() Then
   f_count = DB.GetFieldCount()
End If

GetFieldName

Returns the field name for the field identified by the index passed in as a parameter. The range allowed for the incoming index is from 0 to GetFieldCount() - 1.  Select must be called prior to making calls to this method.

Function GetFieldName( index )

Parameters:
integer - index: a zero-based index of a field.

Return value:
string - the field name for a field located at index.
An exception is thrown in case of errors.

VB Sample

Dim f_count
If DB.Select() Then
   f_count = DB.GetFieldCount()
   Dim name
   For I = 0 To f_count - 1
      name = DB.GetFieldName( I )
   Next
End If


Comments