How do I check if a variable exist before adding it to avoid duplicates?

okaymy1112

Member
Joined
Aug 26, 2014
Messages
6
Programming Experience
Beginner
Can someone help me with this please.
Here is what I am trying to do but I am not sure how to go about it. I think I need to use a For Each loop.
My code in the section with the comment 'Process other identification this is where I want to add For Each to loop and get NCIC number nc:IdentificationID and ProtectionOrderOtherIdentificationTypeCode (NCICNUM).
I would like to loop through and check if that number currently exists (e.g 2222), and if it doesn't, add it.


The following line of code is adding it but it is not checking to see if the number exist first
VB.NET:
 objProtectionOrder.AddCrossReferenceNumber(objXmlCrossReferenceNode.SelectSingleNode("nc:IdentificationID", objXMLNameSpaceManager).InnerText, objXmlCrossReferenceNode.SelectSingleNode("ext:ProtectionOrderOtherIdentificationTypeCode", objXMLNameSpaceManager).InnerText)


When For Each loop reaches the end and no NCIC numbers (nc:IdentificationID) matched, add it using the line of code above.


If For Each loop finds a match, exit loop and give exception message.


I would like the error(exception) text should say something like this:
Protection Order[PO number goes here] already has NCIC number[NCIC number from MNCIS].


Example of exception message:


Protection Order 1400456 already has NCIC number 87654321 associated with it.

Visual Studio 2010 Code

VB.NET:
VB.NET:
Protected Overrides Sub ProcessMessage(ByRef aobjBroker As MessageBroker.Library.v4.Broker, ByRef aobjXmlInputDoc As System.Xml.XmlDocument, ByRef aobjInstantiatedObjectsCollection As Microsoft.VisualBasic.Collection)            MyBase.ProcessMessage(aobjBroker, aobjXmlInputDoc, aobjInstantiatedObjectsCollection)


            Dim strCaseNumber As String
            Dim strProtectionOrderNumber As String
            Dim objNameTable As NameTable
            Dim objXMLNameSpaceManager As XmlNamespaceManager
            Dim objXmlServiceNode As XmlNode
            Dim objProtectionOrder As Msc.Integration.Mncis.Library.v4.ProtectionOrder
            Dim objXmlCrossReferenceNode As XmlNode
            'create a namespace manager used for queries into inputmessage (because of namespace)
            objNameTable = New NameTable
            objXMLNameSpaceManager = New XmlNamespaceManager(objNameTable)
            objXMLNameSpaceManager.AddNamespace("ext", "http://www.courts.state.mn.us/ProtectionOrderExtension/1.0")
            objXMLNameSpaceManager.AddNamespace("nc", "http://niem.gov/niem/niem-core/2.0")




            strCaseNumber = aobjXmlInputDoc.DocumentElement.SelectSingleNode("ext:CourtFileNumber", objXMLNameSpaceManager).InnerText
            strProtectionOrderNumber = aobjXmlInputDoc.DocumentElement.SelectSingleNode("ext:ProtectionOrderID", objXMLNameSpaceManager).InnerText
            objProtectionOrder = Msc.Integration.Mncis.Library.v4.ProtectionOrder.Get(strCaseNumber, CInt(strProtectionOrderNumber), False)




            'Process service 
            For Each objXmlServiceNode In aobjXmlInputDoc.DocumentElement.SelectNodes("ext:ProtectionOrderService", objXMLNameSpaceManager)


            Next






            'Process other identification
            objXmlCrossReferenceNode = aobjXmlInputDoc.DocumentElement.SelectSingleNode("ext:ProtectionOrderOtherIdentification", objXMLNameSpaceManager)


            If Not objXmlCrossReferenceNode Is Nothing Then
                'objProtectionOrder.AddCrossReferenceNumber(objXmlCrossReferenceNode.SelectSingleNode("ext:ProtectionOrderOtherIdentificationTypeCode", objXMLNameSpaceManager).InnerText, objXmlCrossReferenceNode.SelectSingleNode("nc:IdentificationID", objXMLNameSpaceManager).InnerText)
                objProtectionOrder.AddCrossReferenceNumber(objXmlCrossReferenceNode.SelectSingleNode("nc:IdentificationID", objXMLNameSpaceManager).InnerText, objXmlCrossReferenceNode.SelectSingleNode("ext:ProtectionOrderOtherIdentificationTypeCode", objXMLNameSpaceManager).InnerText)
            End If




            'Save updates
            Msc.Integration.Mncis.Library.v4.Odyssey.SaveUpdates(CType(objProtectionOrder, Msc.Integration.Mncis.Library.v4.IApiObject))


        End Sub
 
Last edited:
Back
Top