?
Solved

If...Then, Comparing Structures

Posted on 2005-02-24
4
Medium Priority
?
274 Views
Last Modified: 2010-04-23
Is it possible to compare structures in a manner like this....

public archived as firstline
public newline as firstline

Public Structure firstline
        Public packcnt, open, min, record, queue As String
    End Structure

public sub compare

if newline = archived then
newline = nothing
exit sub
elseif newline <> archived then
archvied = newline
end if

end sub

how would I get this to work, it does not like the '=' sign or 'Is' , any suggestions?
0
Comment
Question by:addicktz
[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
4 Comments
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 2000 total points
ID: 13398764
you can create a compare sub within the structure...

public archived as firstline
public newline as firstline

Public Structure firstline
   Public packcnt, open, min, record, queue As String

   public function Equals(fl as firstline) as boolean
      return (me.packcnt = fl.packcnt and me.open = fl.open and me.min = fl.min and me.record = fl.record and me.queue = fl.queue)
   end function      
End Structure

public sub compare

if newline.equals(archived) then
   newline = nothing
   exit sub
else
   archvied = newline
end if

end sub
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 13399062
Not with VB.NET.  VB.NET doesn't support Operator Overloading.

However, if you define the firstline Structure in C#, you could overload the Equals and NotEquals operators to allow VB.NET apps using the Structure to compare the instances as you did in your compare sub above.
0
 
LVL 4

Expert Comment

by:Koala119
ID: 13399133
newline and archived are always assigned to the same structures? If you just want to compare the values of the packcnt, open, min, record, queue of newline and archived, you can use newline.Equals(archived) to compare all values:

        If newline.Equals(archived) Then
            newline = Nothing
            Exit Sub
        ElseIf Not newline.Equals(archived) Then
            archived = newline
        End If


But if newline and archived belong to different structure names, it will not work...
0
 
LVL 2

Expert Comment

by:lordicarus
ID: 13428653
bricrowe was correct with his approach... just need to add the overloads keyword...

    Public Structure firstline
        Public packcnt, open, min, record, queue As String

        Public Overloads Function Equals(ByVal fl As firstline) As Boolean
            Return (Me.packcnt = fl.packcnt And Me.open = fl.open And Me.min = fl.min And Me.record = fl.record And Me.queue = fl.queue)
        End Function
    End Structure
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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