Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User types

Status
Not open for further replies.

bronc

Instructor
Aug 28, 2003
145
GB
I defined this type in a code module

Type PersonInfo
SurName As String * 10
Age As Integer
End Type

and then

Private Sub CommandButton1_Click()
Dim Person1 As PersonInfo, Person2 As PersonInfo
Person1.SurName = "ed"
Person1.Age = 21
Person2 = Person1

MsgBox Person2.SurName
MsgBox Person2.Age

End Sub

to my surprise it worked ie i could put one object equal to another.

does anyone know if equality can be TESTED

ie IF (Person2 = Person1) without iterating thru all of the members?


thanks

 
create an equals method:

Code:
Public Function PersonEquals(person1 as Person, person2 as Person) as Boolean
If person1.Property1 <> person2.Property1 Then PersonEquals = False : Exit Function
' ...
PersonEquals = True
End Function


mr s. <;)

 
well i think the answer is no but i much appreciate the thought provoking suggestions

thanks

 
without iterating through all of the members

hmm. i think you're not understanding what equality does in respect of reference types.

"a = b" says "is the area of memory pointed at by variable a the same one pointed at by b?" if they are, the values of the individual members will, by definition, be the same.

if they're not and i want to check that this object in this area of memory refers to the same data as this other object, in vba i have no choice but to go through the members one at a time to test them.

if you want to get all winapi and pointery, you could cast the objects to something like a string, and then check all the members at once. good luck with that.

hth,


mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top