addicktz
asked on
If...Then, Comparing Structures
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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...
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...
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
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
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.