Solved

Comparing UDTs in VB !!

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

770 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