Your code will not compile with Option Strict On because
directcast(wathever,control).tag is of type Object and the operator = is not
allowed with operands of type Object.
However directcast(whatever,datarow).item(y).tostring is interesting.
Intellisense does not tell me that ToString is a method of Object but the
help files do. This means that I can write "If objFirst.ToString =
objSecond.ToString Then". As I have already verified they are the same type,
e.g. both Integer or both String, then if their values are the same, their
string representation should be the same. Conversely if their string
representation is different then they must have started out with different
values.
Thus,
Option Strict On
Public Shared Function ObjectValuesAreEqual(ByVal FirstObject As Object,
ByVal SecondObject As Object) As Boolean
If FirstObject.GetType.Equals(SecondObject.GetType) Then
If FirstObject.ToString = SecondObject.ToString Then
Return True
End If
End If
Return False
End Function
Thanks,
George.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OU**************@TK2MSFTNGP12.phx.gbl...
George,
Take forever the highest class where the property is still in so probably
in your situation.
If directcast(wathever,control).tag =
directcast(whatever,datarow).item(y).tostring
I hope this helps?
Cor
"George" <ge****@george.com> .. 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.