Parsing To A Character Type

It is my code doing that, same as in the attachment. Your code doesn't work with more than 2 lines of text in the message. i.e., If I put a full, complete message here like so:

MSGID/TEST-MESSAGE/FROM-A-PIMP/023//
P/-/1234/Test/Test/Test//
REF/B/PHONECON/20SEP2006//
T/1257PM/PACIFIC STANDARD TIME//
REMARKS/NOTHING FURTHER TO REPORT//
 
I do believe it's the code creating the problems.

In Public Sub ParseMSG (modInputMsg):

strFileToParse = "MSGID/TEST-MESSAGE/FROM-A-PIMP/023//P/-/1234/Test/Test/Test//"
' this line produces what's getting into your table
strFileToParse = Trim(Right(strFileToParse, Len(strFileToParse) - InStr(strFileToParse, "P/") + 1))
? strFileToParse
P/023//P/-/1234/Test/Test/Test//

strFileToParse = "MSGID/TEST-MESSAGE/FROM-A-PIMP/023//P/-/1234/Test/Test/Test//"

Try replacing the line in red (above) with this:
strFileToParse = mid(strFileToParse, instr(strFileToParse, "//")+ 2)
? strFileToParse
P/-/1234/Test/Test/Test//

Bob
 
Bob,

Whoa! That worked!! I need to digest how, at that moment and point it does, but now I can see why you were getting frustrated that it was working on your end...lol

I'm gonna play with it a bit and report back final findings and a clean email parsing version for the code repository once done. Thank you again, my command and I appreciate it!
 
Alright! Maybe we're finally getting somewhere.

I'm somewhat crippled since I can't get the messages into Outlook, thus I can't run the complete code.

Think you're going to have to step thru it line-by-line to see if there are other problems of similar nature. I suggest testing each line of code containing InStr, Left or Right to see what's being output. Easy way might be to add a Debug.Print following the lines in question.

Bob

Added: You gotta watch them PIMP/'s, they'll do you in every time.
 
Last edited:
I plugged that code in for the MSGID processing section... no joy.

Code:
'Move to MSGID line, determine Message Type, Originator, and Serial Number
    If InStr(strFileToParse, "MSGID/") <> 0 Then
    
        'strFileToParse = Trim(Right(strFileToParse, Len(strFileToParse) - InStr(strFileToParse, "MSGID/") + 1))
[COLOR=Red][B]         strFileToParse = Mid(strFileToParse, InStr(strFileToParse, "//") + 2)[/B][/COLOR]
        If InStr(strFileToParse, "//") <> 0 Then
            
            strLineToParse = CleanString(Left(strFileToParse, InStr(strFileToParse, "//") + 1))
            strMSGID = strLineToParse
            MsgBox strMSGID
            
            'get Message Type
            strMSGTYPE = GetStringBeforeTheNthDelimitor(strLine:=strLineToParse, intNthDelimitorNumber:=2)
            'get Originator
            strFROM = GetStringBeforeTheNthDelimitor(strLine:=strLineToParse, intNthDelimitorNumber:=3)
            'get Serial Number
            strSERIAL = GetStringBeforeTheNthDelimitor(strLine:=strLineToParse, intNthDelimitorNumber:=4)
                               
        End If
    Else
    End If
It seems that the fFindNthOccur function is only working for a P/ line parsing, not any other line, in this case MSGID. Do I need to make another function, tailored for the MSGID line?

*EDIT: Ok, my first guess long ago was correct, your code is grabbing the line within the "//". If I edit my test email and put a // in front of the word MSGID, the above code works. However, I don't have that luxury to add anything to the 1000's of messages I have to parse. So for any lines after the MSGID line, your code will work, based on all preceding lines ending in a //, so we just gotta crack the nut the MSGID line, since it doesn't have a line preceding it ending in //.
 
Last edited:
Figured it out!!!

Each line in the message ends with a carriage return and a line feed. Using a book I bought, Mastering VBA for MS Office, I figured out how to look for that, then the start of the line using the built in constant for carriageretun & line feed: vbCrLf

Code:
Dim strPCR As String
strPCR = vbCrLf & "P/"                          
strFileToParse = Trim(Right(strFileToParse, Len(strFileToParse) - InStr(strFileToParse, strPCR) + 1))
Works like a champ every time! Sorry for the troubles Bob, but thank you for the help, it taught me quite a few things!
 
Hi -

Sorry for the delay in getting back to you.

Glad the vbCrLf works for you. However, how 'bout the rest of it?

I ask because, in my opinion, your explanation in Post #25 is incorrect and is not going to do what you're looking for. If you'll look at post #18, you'll note all of the test messages are virtually identical, and I grabbed them based on the "//" at the end of the section, not the beginning. You were catching "P/" because that's what you were selecting on, rather than "//".

If you're still having problems, would it be possible to provide some test messages that are not read only?

Best wishes, Bob
 
Last edited:

Users who are viewing this thread

Back
Top Bottom