getValue Method
Returns the value of the field at the specified position in the record.
Script Syntax
value = objRecord.getValue( index );
value = objRecord.getValue( fieldName );
Parameters
- index
- An integer containing the 0-based index of the field in the query output records. The index must be less than the number of fields returned by the getColumnCount method of the LogRecordSet object.
- fieldName
- A string containing the name of the field in the query output records.
Return Value
The value of the specified field.The value is returned as a VARIANT (i.e. a scripting variable) whose type depends on the data type of the field. The following table shows the VARIANT type returned and the corresponding scripting types for each of the Log Parser data types:
Field Type | VARIANT Type | JScript Type | VBScript Type |
---|---|---|---|
INTEGER | VT_I4 | number | Long |
REAL | VT_R8 | number | Double |
STRING | VT_BSTR | string | String |
TIMESTAMP | VT_DATE | date (VB date) | Date |
NULL | VT_NULL | null object | Null |
Remarks
- Some scripting languages might not handle correctly the null value returned by the getValue method when the field at the specified location is NULL. In these cases, call the isNull method before the getValue method to test the field for NULL values.
-
Although the Log Parser INTEGER Data Type is a 64-bit value,
the getValue method returns INTEGER values as 32-bit integers, since scripting languages
do not handle correctly 64-bit integer values.
This means that truncation might occur when values are larger than the maximum
32-bit value.
In these cases, if a low-level programming language is being used (e.g. C++), applications can call the getValueEx method to retrieve INTEGER values as 64-bit values.
Examples
JScript example:
var oLogQuery = new ActiveXObject("MSUtil.LogQuery"); // Create query text var strQuery = "SELECT TimeGenerated, SourceName, EventID, Message FROM System"; // Execute query and receive a LogRecordSet var oRecordSet = oLogQuery.Execute( strQuery ); // Visit all records while( !oRecordSet.atEnd() ) { // Get a record var oRecord = oRecordSet.getRecord(); // Display record information WScript.Echo( "TimeGenerated: " + oRecord.getValue("TimeGenerated") ); WScript.Echo( "SourceName : " + oRecord.getValue(1) ); WScript.Echo( "EventID : " + oRecord.getValue(2) ); if( !oRecord.isNull(3) ) { WScript.Echo( "Message : " + oRecord.getValue(3) ); } else { WScript.Echo( "Message : <null>" ); } // Advance LogRecordSet to next record oRecordSet.moveNext(); } // Close LogRecordSet oRecordSet.close();VBScript example:
Dim oLogQuery Dim oRecordSet Dim strQuery Dim f Dim val Set oLogQuery = CreateObject("MSUtil.LogQuery") ' Create query text strQuery = "SELECT TimeGenerated, SourceName, EventID, Message FROM System" ' Execute query and receive a LogRecordSet Set oRecordSet = oLogQuery.Execute( strQuery ) ' Visit all records DO WHILE NOT oRecordSet.atEnd ' Get a record Set oRecord = oRecordSet.getRecord ' Display record information WScript.Echo "TimeGenerated: " & oRecord.getValue("TimeGenerated") WScript.Echo "SourceName : " & oRecord.getValue(1) WScript.Echo "EventID : " & oRecord.getValue(2) If oRecord.isNull(3) = False Then WScript.Echo "Message : " & oRecord.getValue(3) Else WScript.Echo "Message : <null>" End If ' Advance LogRecordSet to next record oRecordSet.moveNext LOOP ' Close RecordSet oRecordSet.close
See also:
LogRecord ObjectLog Parser COM API Overview
C# Example