Development‎ > ‎VBScript‎ > ‎

Dictionary Dumper


Code:
'*********************************************************************************
'* Function signature:
'* Description:
'*                  
'*
'* Parameters
'*
'*
'*
'* Return Value
'*
'*********************************************************************************
Class ObjectPrinterClass
      Dim sDefaultTitle
     
      Sub Class_Initialize
            sDefaultTitle = "Object Printer - " 
      End Sub
     
      Public Sub Dictionary(dicObject)
            Dim sMessage : sMessage = "Dictionary dumper: " & vbNewLine
           
            'Create message and capture possible errors
            On Error Resume Next
                  For each key in dicObject.Keys
                        sMessage = sMessage & """" & key & """ <=> """ & dicObject.Item(key) & """" & vbNewLine
                  Next
                 
                  If err.Number > 0 Then
                        sMessage = err.Number & "#: " & err.Description
                  End If
            On Error Goto 0   
           
            'Display the object
            MsgBox sMessage, vbOk, sDefaultTitle & "Dictionary Object"
      End Sub
 
 
      Public Sub UnitTest
            'Create dictionary object and add some items to it
            Dim dicUserNames : set dicUserNames = createobject("Scripting.Dictionary")
            dicUserNames.add "Item#1", "val#1"
            dicUserNames.add "Item#2", "val#2"
            dicUserNames.add "Item#3", "val#3"
            dicUserNames.add "Item#4", "val#4"
           
            'Display object
            Dictionary dicUserNames
            Set dicUserNames = Nothing
      End Sub
End Class

Dim ObjectDisplay : Set ObjectDisplay = New ObjectPrinterClass 

'To unit test the class
ObjectDisplay.UnitTest

Comments