2 Replies - 1100 Views - Last Post: 18 February 2013 - 09:24 AM Rate Topic: -----

#1 Mbula  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-February 13

Parsing SWIFT MT103 files

Posted 18 February 2013 - 12:20 AM

[Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'OpenFD.ShowDialog()
        Dim Str As New System.Text.StringBuilder
        Dim closed As New System.Text.StringBuilder
        'Dim oReader As StreamReader

        OpenFD.CheckFileExists = True
        OpenFD.CheckPathExists = True
        OpenFD.DefaultExt = "out"
        OpenFD.FileName = ""
        OpenFD.Filter = "Swift Files (*.out)|*.out|All Files (*.*)|*.*"
        OpenFD.Multiselect = True
        If OpenFD.ShowDialog = Windows.Forms.DialogResult.OK Then

            ' For Each oReader2 As FileInfo In New DirectoryInfo(OpenFD).GetFiles("*.out") '= New StreamReader(OpenFD.FileName, True)
            'oReader2.Append(File.ReadAllText(Str.FullName))
            'Str.Append(oReader.ReadToEnd)
            For Each f As FileInfo In New DirectoryInfo("C:\Users\HP\Desktop\SWIFT MT103").GetFiles("*.out")
                Str.Append(File.ReadAllText(f.FullName))
            Next
            RichTextBox1.Text = Str.ToString()
            'oReader.Close()
        End If

        'Here --> File Split Code
        Dim pattern As String = ":" 'Split on ':' 

        Dim input As String = RichTextBox1.Text
        Dim substrings() As String = Regex.Split(input, pattern)

        Dim arrList As New List(Of String)

        'Declare Strings to hold the values that will be inserted into the database
        Dim F20, F23B, F32A, F33B, F36, F50k, F51A, F52A, F53AB, F54A, F55A, F56A, F57AD, F59A, F70, F71A, F71G, F71F, F72 As String
        Dim myString20 As String = "20"
        Dim myString23B As String = "23B"
        Dim myString32A As String = "32A"
        Dim myString33B As String = "33B"
        Dim myString36 As String = "36"
        Dim myString50 As String = "50K" 'Or "50"
        Dim myString51A As String = "51A"
        Dim myString52A As String = "52A"
        Dim myString53 As String = "53A" 'Or "53B"
        Dim myString54A As String = "54A"
        Dim myString55A As String = "55A"
        Dim myString56A As String = "56A"
        Dim myString57 As String = "57A" 'Or "57D"
        'Dim myString59X As String = "59A"
        Dim myString59 As String = "59"
        '
        Dim myString59A As String = "59"
        Dim myString70 As String = "70"
        Dim myString71A As String = "71A"
        Dim myString71G As String = "71G"
        Dim myString71F As String = "71F"
        Dim myString72 As String = "72"

        Dim sd As Array = substrings.ToArray
        'create indexes for the values
       
        Dim myIndex As Integer = Array.IndexOf(sd, myString20)
        Dim myIndex1 As Integer = Array.IndexOf(sd, myString23B)
        Dim myIndex2 As Integer = Array.IndexOf(sd, myString32A)
        Dim myIndex3 As Integer = Array.IndexOf(sd, myString33B)
        Dim myIndex4 As Integer = Array.IndexOf(sd, myString36)
        Dim myIndex5 As Integer = Array.IndexOf(sd, myString50)
        Dim myIndex6 As Integer = Array.IndexOf(sd, myString51A)
        Dim myIndex7 As Integer = Array.IndexOf(sd, myString52A)
        Dim myIndex8 As Integer = Array.IndexOf(sd, myString53)
        Dim myIndex9 As Integer = Array.IndexOf(sd, myString54A)
        Dim myIndex10 As Integer = Array.IndexOf(sd, myString55A)
        Dim myIndex11 As Integer = Array.IndexOf(sd, myString56A)
        Dim myIndex12 As Integer = Array.IndexOf(sd, myString57)
       
        Dim myIndex13 As Integer = Array.IndexOf(sd, myString59A)
        'declare another for 59
        Dim myIndex19 As Integer = Array.IndexOf(sd, myString59)

        Dim myIndex14 As Integer = Array.IndexOf(sd, myString70)
        Dim myIndex15 As Integer = Array.IndexOf(sd, myString71A)
        Dim myIndex16 As Integer = Array.IndexOf(sd, myString71F)
        Dim myIndex17 As Integer = Array.IndexOf(sd, myString71G)
        Dim myIndex18 As Integer = Array.IndexOf(sd, myString72)


        'Console.WriteLine(myString36, myIndex4)
        'RichTextBox2.Text = (sd(myIndex + 1))
        'Assign the Field Variables values to insert into db
        F20 = (sd((myIndex + 1)))
        ' F23B, F32A, F33B, F36, F50k, F51A, F52A, F53AB, F54A, F55A, F56A, F57AD, F59A, F70, F71A, F71G, F71F, F72
        F23B = (sd((myIndex1 + 1)))
        F32A = (sd((myIndex2 + 1)))


        If (sd((myIndex3 + 1)) = "") Then
            F33B = "null"
        Else
            F33B = (sd((myIndex3 + 1)))
        End If
        'Check if string 59 or 59A exists and assign the variable f59A
        If ((sd((myIndex13 + 1)) = "") And (sd((myIndex19 + 1)) = "")) Then
            F59A = sd(myIndex19 + 1)
        Else
            F59A = sd(myIndex13 + 1)
        End If

        'Condition
        If (sd((myIndex4 + 1)) = "") Then
            F36 = "null"
        Else
            F36 = (sd((myIndex4 + 1)))
        End If

        F50k = (sd((myIndex5 + 1)))
        F51A = (sd((myIndex6 + 1)))
        F52A = (sd((myIndex7 + 1)))
        F53AB = (sd((myIndex8 + 1)))
        F54A = (sd((myIndex9 + 1)))
        F55A = (sd((myIndex10 + 1)))
        F56A = (sd((myIndex11 + 1)))
        F57AD = (sd((myIndex12 + 1)))
        'F59A = (sd((myIndex13 + 1)))
        F70 = (sd((myIndex14 + 1)))
        F71A = (sd((myIndex15 + 1)))
        F71G = (sd((myIndex16 + 1)))
        F71F = (sd((myIndex17 + 1)))

        'capture the value at F72 and split using 
        Dim val As String = (sd((myIndex18 + 1))) 'capture the entire string with {}
        Dim myInteger As Integer 'declare an integer to hold the index of the value to search
        myInteger = val.IndexOf("-")  ' myInteger = 17 get the index of the minus sign
        Dim count As Integer 'create a counter to take count of the number of items in the string
        For count = 0 To (myInteger - 1) 'set the range tobe between the first character and the one just before the searched items
            closed.Append(val(count)) 'append the items into a stringbuilder/concatenate the items
        Next 'loop through until all items are inserted into the string builder
        Dim lastf72 As String = closed.ToString() 'create another string to contain the values held in the stringbuilder

        F72 = lastf72 'assign the column the value obtained

        'finish by opening the transaction,run the query and display DB content to a data grid 
        connection.Open()
        UpdateRecord("insert into mt(ID, TRefNumber20,BankOperCode23B,ValueDate32A,Currency33B,ExchangeRate36,OrderingCustomer5050K,SendingInstruction51A,OrderingInstitution52A,SendersCorrespondent53A53B,ReceiversCorrespondent54A,ThirdReimbursement55A,Intermediary56A,AccountWithInstitution57A57D,Beneficiary5959A,RemittanceInfo70,Detailsofcharges71A,Senderscharges71G,Receivercharges71F,SendertoReceiverinfo72) VALUES ('','" + F20 + "','" + F23B + "','" + F32A + "','" + F33B + "','" + F36 + "','" + F50k + "','" + F51A + "','" + F52A + "','" + F53AB + "','" + F54A + "','" + F55A + "','" + F56A + "','" + F57AD + "', '" + F59A + "','" + F70 + "', '" + F71A + "', '" + F71G + "', '" + F71F + "','" + F72 + "')")
        connection.Close()
]





Im trying to read all files in the folder "SWIFT MT103" split the files and save the content into a Db. Im having a problem skipping all blocks of statement in the file that are enclosed in opening or closing curly braces and saving the individual files a separate records to the database. attached is an example of the SWIFT files that Im working with

This post has been edited by modi123_1: 18 February 2013 - 09:21 AM
Reason for edit:: fixed botched code tag


Is This A Good Question/Topic? 0
  • +

Replies To: Parsing SWIFT MT103 files

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Parsing SWIFT MT103 files

Posted 18 February 2013 - 08:14 AM

Two problems, one is that you didn't place your code inside code tags. You can do this manually, like this... :code: or by highlighting all the code you pasted and clicking the CODE icon above the message editor.

More importantly, there was no attached file, so it's pretty much impossible for anyone to figure out your problem. If you are having trouble attaching a file, you could use a service like DropBox or similar to upload the file, and give us a link to it.

This post has been edited by lar3ry: 18 February 2013 - 08:16 AM

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8374
  • View blog
  • Posts: 31,122
  • Joined: 12-June 08

Re: Parsing SWIFT MT103 files

Posted 18 February 2013 - 09:24 AM

SWIFT as in "Society for Worldwide Interbank Financial Telecommunication" files?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1