Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Comparing UDTs in VB !!

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
RAFAAJ
Asked:
RAFAAJ
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
tguezCommented:
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now