Parsing Text

G

grep

I'm having a devil of a time getting a parsing script to work, and am
hoping desperately for some guidance.

Here's the script thusfar - please understand that there's actually more
to it, but I'm finding troubleshooting scripts run from a rule to be
terribly difficult to troubleshoot (breakpoints don't seem to work) and
have to break things up to figure out where the problems are:

Sub TestScript(objMessage As Outlook.MailItem)

Dim arrLabels, arrData
Dim arrBody() As String
Dim strReadLine, strLabel
Dim intLocLabel As Integer
Dim intLocCRLF As Integer
Dim intLenLabel As Integer
Dim i

arrLabels = Array("Username:", "BackupSet:")
'Get message body and put each line into an array
arrBody = Split(objMessage.Body, vbCrLf)
For i = 0 To UBound(arrBody)
strReadLine = arrBody(i)
For Each strLabel In arrLabels
intLocLabel = InStr(strReadLine, strLabel)
intLenLabel = Len(strLabel)
If intLocLabel > 0 Then
MsgBox strLabel & " " & inLocLabel
End If
Next
Next
End Sub

Now, all this should do is find the labels, and display them and their
locations, if found. This script, thusfar, produces absolutely no
results. If I take out the If clause, however, and just replace it with
something like, MsgBox strLabel & " " & intLocLabel, that will work. I
get results like,

Username: 0
BackupSet: 0
until it reaches one that actually works, where it might say,

Username: 6
BackupSet: 0

or something like that.

So two questions here:

1. Why is the current rendition not working?
2. Is there a better way to test this script?
 
E

Eric Legault [MVP - Outlook]

The only thing I see wrong is this line:

MsgBox strLabel & " " & inLocLabel

It should be intLocLabel. Other than that, I recommend adding Option
Explicit to the header of the module and make sure that the VBA project can
compile. If it does, you should be able to use breakpoints to step through
your code, unless the rule is not firing properly.
 
G

grep

Eric,

Oops - mea culpa on that one. That was the reason that I couldn't see
any results. Unfortunately, this still doesn't solve my underlying problems:

1. When running the code from a rule, breakpoints don't
seem to apply. There seems to be no way to debug
the code, short of inserting my own breakpoints
via MsgBox. These don't really give me breakpoints,
but at least they might let me see the values of my
variables.

2. Not only do breakpoints not seem to work, but errors
seem to just cause complete failures. One error in the
code, and the entire code will just breeze through
with no results, and no explanations. You have to guess.
Pre-compiling does nothing more than help me spot
problems with syntax, or undeclared variables. (Note:
I have already been running with Option Explicit turned
on, but still receive no error messages.)

3. The *only* apparent way to run the code is by actually
selecting Tools | Rules | Run Rules Now. I have to do
this every time I want to test *anything*. This is
because I'm relying on Outlook to pass the MailItem
object as a parameter to the code. Thus, I can't
just run it as a macro - there would be nothing to
pass.

For example, please consider this new expanded code:

Option Explicit
Sub TestScript(objMessage As Outlook.MailItem)

Dim arrLabels
Dim arrBody(), arrData()
Dim strReadLine, strLabel, strData
Dim intLocLabel As Integer
Dim intLenLabel As Integer
Dim i, j

arrLabels = Array("Username:", "BackupSet:", _
"Status:", "Transferred:", "Bytes:", _
"Storage Used:", "Quota:")
j = 0
'Get message body and put each line into an array
arrBody = Split(objMessage.Body, vbCrLf)
For i = 0 To UBound(arrBody)
strReadLine = arrBody(i)
For Each strLabel In arrLabels
intLocLabel = InStr(strReadLine, strLabel)
intLenLabel = Len(strLabel)
If intLocLabel > 0 Then
intLocLabel = intLocLabel + intLenLabel
strData = Mid(strReadLine, intLocLabel)
arrData(j) = Trim(strData)
j = j + 1
End If
Next
Next
'The following is just here to show me the values in the array.
MsgBox arrData(0) & vbCrLf & arrData(1) & vbCrLf _
& arrData(2) & vbCrLf & arrData(3) & vbCrLf _
& arrData(4) & vbCrLf & arrData(5) & vbCrLf & arrData(6)

End Sub

Now, I run this code, and see nothing. There may be an error somewhere,
although I did do a compile first which came up clean, but nothing comes
up to tell me so. At this point, I'm thinking of having the script just
dump the damned message to a text file, and then call an awk script to
parse it into a delimited file. I know I can do it in awk, and it would
even be easier to debug.

The problem is, it won't be fully automated, which is really what I'm
going for. Ultimately, the goal is to have the data pumped into an
Access database, and I'd have to do a manual import of the delimited
file to do that. <sigh>

Thanks again for all your help, and for letting me rant.

grep
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top