Since I'm talking about a function that goes into a larger program, I will present examples that work as stand-alone programs. But I will have to fake the message. So, let's say an email might look like this...
I never received a response from anyone about my inquiry. Never spoke
with Scala Rep. Don't remember any correspondence. I wanted to know
the price of the software.
-----Original Message-----
From: Scala Sales [mailto:Someone@Scala.com]
Sent: Thursday, July 01, 2004 9:05 AM
To: Prospect
Subject: RE: Company, State, Country
Prospect,
We have noticed the last update to your discussion with Scala Rep
regarding "Company, State, Country" was 7 days ago. If you
like, you can follow the included link...
http://www.scala.com/message/?59483475213687
...and log in with the email address noone@nowhwere.com to
let us know how your endeavors are proceeding. You can also reach
Scala Rep by telephone at (555) 123-4567.
Regards,
Scala Sales |
Now, to include this fake email in the test program, we will need to populate a variable with this email as its contents. Make a new text file. Name it ExtractID.vbs and put the following code into it...
myFakeEmail = "" & _
"I never received a response from anyone about my inquiry. Never spoke" & vbNewLine & _
"with Scala Rep. Don't remember any correspondence. I wanted to know" & vbNewLine & _
"the price of the software." & vbNewLine & _
"" & vbNewLine & _
"-----Original Message-----" & vbNewLine & _
"From: Scala Sales [mailto:Someone@Scala.com]" & vbNewLine & _
"Sent: Thursday, July 01, 2004 9:05 AM" & vbNewLine & _
"To: Prospect" & vbNewLine & _
"Subject: RE: Company, State, Country" & vbNewLine & _
"" & vbNewLine & _
"Prospect," & vbNewLine & _
"" & vbNewLine & _
"We have noticed the last update to your discussion with Scala Rep" & vbNewLine & _
"regarding ""Company, State, Country"" was 7 days ago. If you" & vbNewLine & _
"like, you can follow the included link..." & vbNewLine & _
"" & vbNewLine & _
"http://www.scala.com/message/?59483475213687" & vbNewLine & _
"" & vbNewLine & _
" ...and log in with the email address noone@nowhwere.com to" & vbNewLine & _
"let us know how your endeavors are proceeding. You can also reach" & vbNewLine & _
"Scala Rep by telephone at (555) 123-4567." & vbNewLine & _
"" & vbNewLine & _
"Regards," & vbNewLine & _
"" & vbNewLine & _
"Scala Sales" & vbNewLine & _
"" |
As usual, there are nuances to point out. First, is the use of the underscore character. Underscores are a way of appending together multiple lines of a program into one. This keeps you from having to write consecutive lines that look like...
myFakeEmail = myFakeEmail & "line 1" & vbNewLine
myFakeEmail = myFakeEmail & "line 2" & vbNewLine
myFakeEmail = myFakeEmail & "line 3" & vbNewLine
Instead, you write....
myFakeEmail = myFakeEmail & "line 1" & vbNewLine & _
"line 2" & vbNewLine & _
"line 3" & vbNewLine
So, why do I have the extra empty lines at the top and bottom? It's just a technique I use, so the first and last lines of the real body of the message are not special exceptions. I can copy and paste between the empty lines, and run the same macro on every line to fill in the quotes and underscores.
The next thing to point out is the infamous VB double-double quotes. This is the way to escape a quote, since a quote in VBScript (and many other languages) is the way of containing a string literal. I could have also appended a Chr(34) with the same results. I do it this way out of habit.
The next thing to point out is the vbNewLine's. I use them to reproduce the line breaks that would exist in the actual email. As we will learn later, the actual placement of the line break is important, as is whether there is a trailing space after the text for which we will be looking.
This WSH script will actually run fine, even though it doesn't display any output. |