[SOLVED]Text Parsing Issue (1 Viewer)

riti90

Registered User.
Local time
Today, 04:24
Joined
Dec 20, 2017
Messages
44
I opened your NotGoodList and copied it to Notepad++ and saved the file as iptvOrig.txt

I changed this line of code:
Code:
   ' Open "C:\Users\mp\Desktop\tv_channels_hjh14m2636_plus.txt" For Input As #1
   Open "C:\Users\jack\documents\iptvorig.txt" For Input As #1
I stepped through the code and checked a few values for a record or 2.
Then ran the code directly from the module. Saw that the table was populated, so deleted the records;
then ran the routine from the form button.
well if you save it from Notepad++ it works just fine, it becomes formatted just like the Good List, but I was wondering if we could find a way on how to parse it when it is not formatted.. It may be too much to ask, I don't know..

Regards,
Margarit
 

namliam

The Mailman - AWF VIP
Local time
Today, 05:24
Joined
Aug 11, 2003
Messages
11,695
but I was wondering if we could find a way on how to parse it when it is not formatted.. It may be too much to ask, I don't know..
My code as is works, or atleast for tvg-name.

What did you try to do that did not work?
 

riti90

Registered User.
Local time
Today, 04:24
Joined
Dec 20, 2017
Messages
44
My code as is works, or atleast for tvg-name.

What did you try to do that did not work?
Hi,
Yes it works for the tvg-name, sorry, I was doing something wrong there.
It works just fine :)
I just need probably to do the same for all the other bits in the line then?
Any suggestion on that? :)
Thank you
 

namliam

The Mailman - AWF VIP
Local time
Today, 05:24
Joined
Aug 11, 2003
Messages
11,695
Code:
            If Mid(myLine, myCounter, 8) = "tvg-name" Then
                myCounter = myCounter + 8 + 2
                myQuote = InStr(myCounter, myLine, """")
                rs.AddNew
                rs.Fields("tvg-name") = Mid(myLine, myCounter, myQuote - myCounter)
                rs.Update
                myCounter = myCounter + myQuote
            End If
Simply insert above bit for each item you want to actually capture.

Once you done that you need to be a little creative about picking up the bit after the comma...
 

riti90

Registered User.
Local time
Today, 04:24
Joined
Dec 20, 2017
Messages
44
Code:
            If Mid(myLine, myCounter, 8) = "tvg-name" Then
                myCounter = myCounter + 8 + 2
                myQuote = InStr(myCounter, myLine, """")
                rs.AddNew
                rs.Fields("tvg-name") = Mid(myLine, myCounter, myQuote - myCounter)
                rs.Update
                myCounter = myCounter + myQuote
            End If
Simply insert above bit for each item you want to actually capture.

Once you done that you need to be a little creative about picking up the bit after the comma...
hi again, sorry to keep bothering but I add it like this and it doesn't give me expected result:

Code:
    Do While Not EOF(1)
        Line Input #1, myLine
        myCounter = 1
        Do While myCounter <= Len(myLine)
            If Mid(myLine, myCounter, 6) = "tvg-id" Then
                myCounter = myCounter + 6 + 2
                myQuote = InStr(myCounter, myLine, """")
                rs.AddNew
                rs.Fields("length") = Mid(myLine, myCounter, myQuote - myCounter)
                rs.Update
                myCounter = myCounter + myQuote
            End If
            
            If Mid(myLine, myCounter, 8) = "tvg-name" Then
                myCounter = myCounter + 8 + 2
                myQuote = InStr(myCounter, myLine, """")
                rs.AddNew
                rs.Fields("tvgname") = Mid(myLine, myCounter, myQuote - myCounter)
                rs.Update
                myCounter = myCounter + myQuote
            End If
            
            myCounter = myCounter + 1
        Loop
    Loop

Do you think it should be better if I put them in different subs or is there another way you may think of?
Thank You :)
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 23:24
Joined
Jan 23, 2006
Messages
15,379
When I opened your zip, then opened the NotGoodList, in my setup it will open the txt file with Notepad++.
If, as you say, that step is modifying the file and inserting CrLF as a record terminator and working with your existing code, then perhaps you should just append a CrLF on each record in your routine. I haven't checked the actual ASCII characters, but I did not adjust the records intentionally. If I get some time later today I'll check it; I have other things on the go this morning.
Good luck.
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 23:24
Joined
Jan 23, 2006
Messages
15,379
Here's a routine that will take your notGoodList that has LF line terminator, and convert it to CrLf terminators and write the result to a new text file. You'll have o adjust your file name in your routine to open the one with the CrLF.

Then, the new output file runs with your existing code. Let us know if this resolves the issue

Code:
' ----------------------------------------------------------------
' Procedure Name: ConvertLF2CRLF
' Purpose: To convert a txt file that uses LF as line separator (UNIX)
' to CrLF (Windows)
' Procedure Kind: Sub
' Procedure Access: Public
' Author: Jack
' Date: 31-Jan-20
' ----------------------------------------------------------------
Sub ConvertLF2CRLF()
10        On Error GoTo ConvertLF2CRLF_Error
          Dim sLine As String
          Dim oLine As String, i As Integer
         '
         'identify a new output file to contain the CrLf
20        Open "C:\users\jack\documents\NotGoodListREVVcrlf.txt" For Output As #2
        
         'the NotGoodList with just LF line terminator
30        Open "C:\users\jack\documents\NotGoodList.txt" For Input As #1
40        Do While Not EOF(1)
50            Line Input #1, sLine
              'replace all LF with CRLf
60            oLine = Replace(sLine, Chr(10), Chr(13) & Chr(10))
              'write the new records to the output file --now have CrLf line terminator
70            Write #2, oLine
80        Loop
90        Close #1
100       Close #2
110       Debug.Print "-----Finished LF to CrLf Conversion ---"

120       On Error GoTo 0
130       Exit Sub

ConvertLF2CRLF_Error:

140       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ConvertLF2CRLF, line " & Erl & "."

End Sub
 
Last edited:

riti90

Registered User.
Local time
Today, 04:24
Joined
Dec 20, 2017
Messages
44
Here's a routine that will take your notGoodList that has LF line terminator, and convert it to CrLf terminators and write the result to a new text file. You'll have o adjust your file name in your routine to open the one with the CrLF.

Then, the new output file runs with your existing code. let us know if this resolves the issue

Code:
' ----------------------------------------------------------------
' Procedure Name: ConvertLF2CRLF
' Purpose: To convert a txt file that uses LF as line separator (UNIX)
' to CrLF (Windows)
' Procedure Kind: Sub
' Procedure Access: Public
' Author: Jack
' Date: 31-Jan-20
' ----------------------------------------------------------------
Sub ConvertLF2CRLF()
10        On Error GoTo ConvertLF2CRLF_Error
          Dim sLine As String
          Dim oLine As String, i As Integer
         '
         'identify a new output file to contain the CrLf
20        Open "C:\users\jack\documents\NotGoodListREVVcrlf.txt" For Output As #2
        
         'the NotGoodList with just LF line terminator
30        Open "C:\users\jack\documents\NotGoodList.txt" For Input As #1
40        Do While Not EOF(1)
50            Line Input #1, sLine
              'replace all LF with CRLf
60            oLine = Replace(sLine, Chr(10), Chr(13) & Chr(10))
              'wrute the new records to the output file --now have CrLf line terminator
70            Write #2, oLine
80        Loop
90        Close #1
100       Close #2
110       Debug.Print "-----Finished LF to CrLf Conversion ---"

120       On Error GoTo 0
130       Exit Sub

ConvertLF2CRLF_Error:

140       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ConvertLF2CRLF, line " & Erl & "."

End Sub
You sir, are a life saver :)

Thank you so much, the only change i made is from
Code:
Write #2, oLine
to
Code:
Print #2, oLine
And that's because if I need to open an already good list the "Write" code would add extra "" in the line.

Thanks once again,
Margarit :)
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 23:24
Joined
Jan 23, 2006
Messages
15,379
Happy to help. Good luck with your project.
 

namliam

The Mailman - AWF VIP
Local time
Today, 05:24
Joined
Aug 11, 2003
Messages
11,695
hi again, sorry to keep bothering but I add it like this and it doesn't give me expected result:

Code:
    Do While Not EOF(1)
        Line Input #1, myLine
        myCounter = 1
        Do While myCounter <= Len(myLine)
            If Mid(myLine, myCounter, 6) = "tvg-id" Then
                myCounter = myCounter + 6 + 2
                myQuote = InStr(myCounter, myLine, """")
                rs.AddNew
                rs.Fields("length") = Mid(myLine, myCounter, myQuote - myCounter)
                rs.Update
                myCounter = myCounter + myQuote
            End If
           
            If Mid(myLine, myCounter, 8) = "tvg-name" Then
                myCounter = myCounter + 8 + 2
                myQuote = InStr(myCounter, myLine, """")
                rs.AddNew
                rs.Fields("tvgname") = Mid(myLine, myCounter, myQuote - myCounter)
                rs.Update
                myCounter = myCounter + myQuote
            End If
           
            myCounter = myCounter + 1
        Loop
    Loop

Do you think it should be better if I put them in different subs or is there another way you may think of?
Thank You :)
So what result are you expecting? Now you are creating a new record "AddNew" per field, this is probably what you mean as you want it as one recorrd.
Anyways I see you got someone to spoonfeed you a solution regardless, bon chance.
 

Users who are viewing this thread

Top Bottom