Solved

Comparing UDTs in VB !!

Posted on 2006-06-22
5
180 Views
Last Modified: 2010-04-07
Hi there,

Is it possible to compare two  User Defined Variables with operators ie : = > <

Here is an example but it causes an Compile error (Type mismatch)


Type UDTTest
    x As Long
    y As Long
End Type

Sub Test()

    Dim tVar1 As UDTTest
    Dim tVar2 As UDTTest
   
    tVar1.x = 1
    tVar1.y = 2
    tVar2 = tVar1
    MsgBox tVar1 = tVar2

End Sub


I know I could have comapared the Xs and the Ys respectively but I the UDTs I have contain many variables.

How do I compare two User Defined Variables in one go ?

Thanks

0
Comment
Question by:RAFAAJ
5 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
Comment Utility
you have to compare the value individually

for example, create a function:

Public Function IsUDTTestEqual ( d1 as UDTTest, d2 as UDTTest) as boolean
  IsUDTTestEqual  = (d1.x = d2.x) AND (d1.y = d2.y)
End Function


    MsgBoxIsUDTTestEqual ( tVar1 , tVar2 )
0
 
LVL 1

Expert Comment

by:tguez
Comment Utility
Yes, that is right.  For my knowledge this is the only way you can do it.

if this was c langauge, you can do a general function, but in vb I think there is no other way.

Tomer
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now