Best way of comparing values from multiple instances of the same object
Posted on 2006-11-09
I'm trying to figure out the best way of doing this...
On the business side, the application tracks budget information for Clients. Each client can have 0..many Groups. For a Client that has Groups, budgets can exist at just the Client level or the Client level and the Group level.
On the programming side... I have an object, call it Budget, whose properties are populated with values from a stored proc when it's instantiated. It can either take the form of a ClientBudget or a PolicyGroupBudget.
If a Budget is being viewed for a Group, for each field on a form I want to set the value as follows. If the field has a non-null/blank value at the Group level, then use that. If not, then use the Client level value if it is non-null/blank. Otherwise, make the field blank.
I tried to do something like this:
objClient = New BusinessObjects.Budget(Me.ClientID)
objGroup = New BusinessObjects.Budget(Me. GroupID)
MyField.Value = GetObjectValue(objGroup, objClient, FieldName)
And the function would look something like this:
Private Function GetObjectValue(ByVal objGroup As BusinessObjects.Budget, ByVal objClient As BusinessObjects.Budget, ByVal FieldName As String) As Object
If mblnFormIsAClientBudget Then
GetObjectValue = objClient.Fieldname
(More code here…)
Catch ex As Exception
The problem is, it won’t let me do the objClient.FieldName b/c of course, FieldName is a string holding the name of the field to pull.
Does anyone know how to make this work? If not, is there a better way of doing this? I tried doing it right in the original Sub using Iif’s but it got messy.
Thanks so much for the help!