Split a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyanka1915
    New Member
    • Nov 2007
    • 32

    Split a text file

    I want to slipt the following data ....


    189{405.7}25{40 6.7}1{409.7}2{1 .7}909<02.01.13 8.000.9>{0.11}5 32756{401.7}2{4 02.7}0{403.7}1{ 404.12}185.2{40 5.7}25{406.7}1{ 409.7}3{1.7}909 <02.01.138.000. 9>{0.11}532756{ 401.7}2{402.7}1 {403.7}1{404.12 }191{405.7}50{4 06.7}1{409.7}3{ 1.7}909<02.01.1 38.000.9>{0.11} 532756{401.7}2{ 402.7}0{403.7}1 {404.12}185.1{4 05.7}10{406.7}1 {409.7}4{1.7}90 9<02.01.138.000 .9>{0.11}532756 {401.7}2{402.7} 1{403.7}1{404.1 2}191.8{405.7}5 00{406.7}1{409. 7}4{1.7}909...
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    use "Split" function..

    Regards
    Veena

    Comment

    • Ali Rizwan
      Banned
      Contributor
      • Aug 2007
      • 931

      #3
      Hi,
      With which key word you want to split the text.
      Did you want to split the text after every . or { or text between them.

      GOOD LUCK
      ALI

      Comment

      • 9815402440
        New Member
        • Oct 2007
        • 180

        #4
        hi priyanka

        try this code


        Const a = "189{405.7}25{4 06.7}1{409.7}2{ 1.7}909<02.01.1 38.000.9>{0.11} 532756{401.7}2{ 402.7}0{403.7}1 {404.12}185.2{ 405.7}25{406.7} 1{409.7}3{1.7}9 09<02.01.138.00 0.9>{0.11}53275 6{401.7}2{402.7 }1{403.7}1{404. 12}191{40 5.7}50{406.7}1{ 409.7}3{1.7}909 <02.01.138.000. 9>{0.11}532756{ 401.7}2{402.7}0 {403.7}1{404.12 }185.1{ 405.7}10{406.7} 1{409.7}4{1.7}9 09<02.01.138.00 0.9>{0.11}53275 6{401.7}2{402.7 }1{403.7}1{404. 12}191.8{ 405.7}500{406.7 }1{409.7}4{1.7} "
        Dim varBFR
        Dim varBFR1
        Dim varBFR2

        varBFR = Split(a, ">")
        Dim i As Integer
        Dim ii As Integer
        Dim iii As Integer
        For i = 0 To UBound(varBFR)
        varBFR1 = Split(varBFR(i) , "<")
        For ii = 0 To UBound(varBFR1)
        varBFR2 = Split(varBFR1(i i), "}")
        For iii = 0 To UBound(varBFR2)
        Debug.Print varBFR2(iii) & IIf(InStr(1, varBFR2(iii), "{", vbTextCompare) > 0, "}", "")
        Next
        Next
        Next

        regards
        manpreet singh dhillon hoshiarpur

        Comment

        • priyanka1915
          New Member
          • Nov 2007
          • 32

          #5
          Hey thanks guys actually this data save in text file n i have to crunch the data

          From following data i want to retrive the values like
          "189{405.7}25{4 06.7}1{409.7}2{ 1.7}909<02.01.1 38.000.9>{0.11} 532756{401.7}2{ 402.7}0{403.7}1 {404.12}185.2{ 405.7}25{406.7} 1{409.7}3{1.7}



          189
          25
          1
          2
          909
          532756
          2
          0....
          so on

          Thank you
          please help its urgent

          Comment

          • 9815402440
            New Member
            • Oct 2007
            • 180

            #6
            hi priyanka
            try following code

            Dim fso As New FileSystemObjec t
            Dim ts As TextStream
            Set ts = fso.OpenTextFil e("F:\Documen ts and Settings\XPPRES P3\My Documents\1.txt ")
            Dim varBFR
            While Not ts.AtEndOfStrea m
            varBFR = Split(ts.ReadLi ne, "}")
            Dim i As Integer
            For i = 0 To UBound(varBFR)
            Debug.Print Val(varBFR(i))
            Next
            Wend


            regards
            manpreet singh dhillon hoshiarpur

            Comment

            • priyanka1915
              New Member
              • Nov 2007
              • 32

              #7
              Hey thanks manpreet, but it is giving error " complier error" near Set ts = fso.OpenTextFil e("C:\rawdata.t xt").....help me please

              Comment

              • 9815402440
                New Member
                • Oct 2007
                • 180

                #8
                hi priyanka

                add refererence to Microsoft Scripting Runtime. to do this open Project Menu and select Reference option


                regards
                manpreet singh dhillon hoshiarpur

                Comment

                • priyanka1915
                  New Member
                  • Nov 2007
                  • 32

                  #9
                  m attaching the text file just check withy dat
                  Attached Files

                  Comment

                  • priyanka1915
                    New Member
                    • Nov 2007
                    • 32

                    #10
                    hey but its not provide the proper values...

                    Comment

                    • QVeen72
                      Recognized Expert Top Contributor
                      • Oct 2006
                      • 1445

                      #11
                      Hi Priyanka,

                      use this code:
                      Add a ListBox Control to ur Form and Check:

                      [code=vb]
                      Dim MyStr As String
                      Dim TArr
                      Dim i As Long
                      Dim j As Long
                      Dim TempStr As String
                      '
                      List1.Clear
                      MyStr = "189{405.7}25{4 06.7}1{409.7}2{ 1.7}909<02.01.1 38.000.9>{0.11} 532756{401.7}2{ 402.7}0{403.7}1 {404.12}185.2{ 405.7}25{406.7} 1{409.7}3{1.7}"
                      TArr = Split(MyStr, "}")
                      For i = LBound(TArr) To UBound(TArr)
                      Dim NewArr
                      TempStr = TArr(i)
                      If Trim(TempStr) <> "" Then
                      NewArr = Split(TempStr, "{")
                      List1.AddItem NewArr(0)
                      End If
                      Next
                      MsgBox "Over"
                      [/code]

                      Regards
                      Veena

                      Comment

                      • 9815402440
                        New Member
                        • Oct 2007
                        • 180

                        #12
                        Hi Priyanka

                        I am just suggesting the logic. I don't know what values you are expecting. I tried the file you sent, but no error was produced by the code. Because first few lines in the file cannot be used to extract values I have changed the code as follows:

                        [CODE=vb]Dim fso As New FileSystemObjec t
                        Dim ts As TextStream
                        Set ts = fso.OpenTextFil e("F:\Documen ts and Settings\XPPRES P3\My Documents\rawda ta1.txt")
                        Dim varBFR
                        Dim i As Integer
                        Dim strString As String
                        While Not ts.AtEndOfStrea m
                        strString = ts.ReadLine
                        If InStr(1, strString, "}", vbTextCompare) > 0 Then
                        varBFR = Split(strString , "}")
                        For i = 0 To UBound(varBFR)
                        Debug.Print Val(varBFR(i))
                        Next
                        End If
                        Wend[/CODE]

                        But this does not mean that this code will give the actual result you require. This is just to explain the logic. You have to modify the code according to your requirements.

                        Don't test large files in the debug window. You must create a breakpoint and check each value of varBFR(i) and then decide what to do with it.

                        Regards,
                        manpreet singh dhillon hoshiarpur
                        Last edited by Killer42; Nov 6 '07, 02:17 AM. Reason: Added CODE=vb tag

                        Comment

                        • priyanka1915
                          New Member
                          • Nov 2007
                          • 32

                          #13
                          Hey thanks...now I want to add that data in database... any ideas?
                          Last edited by Killer42; Nov 6 '07, 07:01 AM.

                          Comment

                          Working...