Look at the docs on a Hashtable object. The docs say that the foreach of a
Hastable returns a DictionaryEntry object for each object in the Hashtable.
The Value property of the DictionaryEntry is the object stored at that
location in the HashTable. Therefore it follows that if the Type of the
Value property of each DictionaryEntry is of a particular type, then you
could set a variable of that type equal to the Value property and then
access it's properties.
Dim ca as _CompanyAccruals
Dim cd as _CompanyDeductions
For Each de as DictionaryEntry in myHashTable
if typeof de.Value is _CompanyAccruals then
ca = de.Value
' Now get the properties for ca
else
cd = de.Value
' Now get the properties for cd
end if
Next
What might be a better design is if you created and Interface that had
common properties that both object shared and then Implemented that
Interface in both of those object. Then, you'd only need one variable in the
above code snippet to get at the properties that you want to print out,
given these properties are the implementations that each object shared
Is that too much info???
HTH
Steve
"RSH" <wa*************@yahoo.comwrote in message
news:Oi**************@TK2MSFTNGP02.phx.gbl...
>I have two HashTables (_CompanyDeductions,_CompanyAccruals) that contain
several objects each. I am trying to loop through and print the properties
of the objects in the Hashtables:
I am trying to creat a dynamic function that will print all of the
properties of each of the objects stored in the the HashTable. I can't
seem to get at the properties of the objects.
Thanks for any help!
Ron
This does NOT work:
Public Sub Print(ByVal type As String)
Console.WriteLine(vbCrLf)
Dim al As New Hashtable
Dim o As Object
Console.WriteLine("CompanyId:" & _CompanyID & " CompanyName:" &
_CompanyName)
Select Case Type
Case "Deductions"
al = _CompanyDeductions
Case "Accruals"
al = _CompanyAccruals
End Select
If al.Count 0 Then
Console.WriteLine(type & " ID" & vbTab & type & " Name" & vbTab & " Rate")
Console.WriteLine("---------------------------------------")
For Each o In al
Console.WriteLine("{0} : {1}", o.value.Name)
Next
Else
Console.WriteLine("No " & type & " exist for this company")
End If
End Sub