Solved

Comparing UDTs in VB !!

Posted on 2006-06-22
5
183 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 16957986
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
ID: 17040185
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 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