Sdílet prostřednictvím


Printing Item Property Names, Types, and Values

Topic Last Modified: 2006-06-12

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:

  • The value of the item's DAV:contentclass and the parent folder's schema scope. If the item's content class is not defined within the parent folder's schema scope, only the properties actually set for the item appear in the Fields collection. If the content class is defined within the parent folder's schema scope, all properties defined by this class appear within the Fields collection.
    Note   All properties defined by the item's content class appear in the Fields collection, even if the properties have not been set (are empty).
  • The properties that are set on the item but are not defined by the item's content class. You can always get all properties set for an item, whether or not these properties are part of the item's content class definition.

Example

VBScript

Example

' 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)
   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
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