Solved

# If...Then, Comparing Structures

Posted on 2005-02-24
Medium Priority
283 Views
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

LVL 34

Accepted Solution

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

ID: 13399062

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

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

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

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
###### Suggested Courses
Course of the Month8 days, 13 hours left to enroll