Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / July 2004



Tip: Looking for answers? Try searching our database.

Comparing User Defined Type variables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wasim Akram - 30 Jul 2004 21:57 GMT
Hi,

My question is regarding the comparison of two UDT variables.
I don't want a byte-by-byte comparison to see whether they contain same
information or not.

What I want is to check whether they are same variables or not.
For more detail, let me give this example.

I have an array of UDT, say MyArray() as MyUDT.
I also have a function with a ByRef parameter of MyUDT.
Say, Function FindIndexOf(ByRef element as MyUDT) as Integer

This is guaranteed that the parameter is one of the elements of the above
mentioned array.
How can this function find the index of the 'element' in the array?

I think I have provided enough details about my problem.
Can anyone help me in this regard?

Regards,

\W/A\
Don@home.com - 30 Jul 2004 23:07 GMT
>Hi,
>
[quoted text clipped - 19 lines]
>
>\W/A\

Not sure if this will help or not.. But here goes some air code...

Private Type tMyUDT
   Avalible As Boolean 'Is this position Availble?
   Name As String '[Last, First (if any)]
   Age As String 'Somewhere between Birth and Death
   Sex As String '(M)ale, (F)emale, (O)ther
   Parents As Long 'Number of legal parents
   'etc...
   'etc...
End Type

Private taMyUDT() As tMyUDT

Private Sub GetInputFromWhereEver()
Dim element As tMyUDT
Dim lRtn As Long

   With element
       .Name = Text1(0).Text
       .Age = Text1(1).Text
       .Sex = Text1(2).Text
       .Parents = Text1(3).Text
       'etc...
       'etc...
   End With
   'See if On File
   lRtn = FindIndexOf(element)
   If lRtn = -1 Then 'not on file
       'Add it taMyUDT() here
       'Find First element.Availble = True
       'Add Info and set .Avaible = False
   Else
       'Duplicate Entry at Index of lRtn
       'Do what you gota do here...
   End If
   
End Sub

Private Function FindIndexOf(element As tMyUDT) As Long
Dim lLp As Long
   
   For lLp = LBound(taMyUDT) To UBound(taMyUDT)
       If Not taMyUDT(lLp).Avalible Then
           'check to see if a match occures
           With element
               If .Name = taMyUDT(lLp).Name And _
                   .Age = taMyUDT(lLp).Age And _
                   .Sex = taMyUDT(lLp).Sex And _
                   .Parents = taMyUDT(lLp).Parents Then
                   'Found a match
                   Exit For
               End If
           End With
       End If
   Next lLp
   If lLp <= UBound(taMyUDT) Then
       FindIndexOf = lLp
   Else
       FindIndexOf = -1
   End If
End Function

Have a good day...

Don
Bob O`Bob - 30 Jul 2004 23:09 GMT
> Hi,
>
[quoted text clipped - 15 lines]
> I think I have provided enough details about my problem.
> Can anyone help me in this regard?

I think the answer is Is

Something, conceptually, like this:

 for each tempMy in MyArray
     if tempMy Is element then

    Bob
J French - 31 Jul 2004 13:52 GMT
>Hi,
>
[quoted text clipped - 15 lines]
>I think I have provided enough details about my problem.
>Can anyone help me in this regard?

To check whether one UDT is actually the /same/ as another you can use
the undocumented VarPtr function that returns the memory address of a
variable

If VarPtr( UDT1 ) = VarPtr( UDT2 ) Then

I can't think of a case where I have ever needed anything like this,
but you obviously have found one.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.