This example demonstrates how to print the name, type, and value for
each of an item's properties. In this routine, a bound
Microsoft® ActiveX® Data Objects (ADO) Record
object is passed, the
Fields collection for the Record is
enumerated, and the type for each Field is echoed to the console. Where
appropriate, the value for the property is also printed. Properties that are
binary or arrays of bytes are not printed.
When binding to an item in this way, the list of
properties present within the
Fields collection is determined using
the following information:
VBScript
' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
Sub printPropsAndType( Rec )
If Not (VarType(Rec) = vbObject And TypeName(Rec) = "Record") Then
Err.Raise &H80070057 ' E_INVALIDARG
End If
Dim Flds
Set Flds = Rec.Fields
Dim vt
For Each Fld in Flds
vt = VarType(Fld.Value)
WScript.Echo Fld.Name
If vt = 14 Then
WScript.Echo " (Unsupported VARIANT type for VBScript)"
Else
WScript.Echo " " & TypeName(Fld.Value)
End If
If IsArray(Fld.Value) Then
WScript.Echo VarType(Fld.Value)
If VarType(Fld.Value) = 14 Then
WScript.Echo " " & "<array of unprintable>"
ElseIf Not IsPrintable(TypeName(Fld.Value)) Then
WScript.Echo " " & "<array of unprintable>"
Else
temp = Fld.Value
For i = LBound(temp) to UBound(temp)
WScript.Echo " " & temp(i)
Next
End If
Else
If VarType(Fld.Value) = 14 Then
Wscript.Echo " " & "<value unprintable>"
ElseIf Not IsPrintable(TypeName(Fld.Value)) Then
Wscript.Echo " " & "<value unprintable>"
Else
Wscript.Echo " " & Fld.Value
End If
End If
wscript.echo
Next
End Sub
Function IsPrintable(sTypeName)
dim result
Select Case sTypeName
Case "Object"
result = False
Case "Object()"
result = False
Case "Byte"
result = False
Case "Byte()"
result = False
Case "Null"
result = False
Case "Error"
result = False
Case "Error()"
result = False
Case Else
result = True
End Select
IsPrintable = result
End Function