G
George
How do I compare the values of two objects when Option Strict is On?
One of the objects is the Tag property from some control (declared as object
but holding a value, e.g. an Integer or a String or a DateTime or ...).
The other object is the Item property from a DataRow (declared as object but
holding a value, e.g. an Integer or a String or a DateTime or ...).
I can find out that they hold the same type using "If
objFirst.GetType.Equals(objSecond).GetType) Then" but I cannot do "If
objFirst = objSecond Then".
Also I cannot convert them to their real types for comparison because
"CType(objFirst, objFirst.GetType)" does not work.
The Is operator only compares the pointers not the values so is not useful
here. To illustrate the following outputs False even though 2 = 2.
Dim o1 as Object, o2 as Object
o1 = 2
o2 = 2
If o1 Is o2 Then
MsgBox("True")
Else
MsgBox("False")
End If
Any ideas?
George.
One of the objects is the Tag property from some control (declared as object
but holding a value, e.g. an Integer or a String or a DateTime or ...).
The other object is the Item property from a DataRow (declared as object but
holding a value, e.g. an Integer or a String or a DateTime or ...).
I can find out that they hold the same type using "If
objFirst.GetType.Equals(objSecond).GetType) Then" but I cannot do "If
objFirst = objSecond Then".
Also I cannot convert them to their real types for comparison because
"CType(objFirst, objFirst.GetType)" does not work.
The Is operator only compares the pointers not the values so is not useful
here. To illustrate the following outputs False even though 2 = 2.
Dim o1 as Object, o2 as Object
o1 = 2
o2 = 2
If o1 Is o2 Then
MsgBox("True")
Else
MsgBox("False")
End If
Any ideas?
George.