Solved

Comparing UDTs in VB !!

Posted on 2006-06-22
5
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month5 days, 5 hours left to enroll

636 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