Russ
Russ

Reputation: 47

Populating an email with data from IBM i (AS400) screen

I'm trying to grab data from an AS400 screen & populate an email using that data but seem to have bumped into something I'm struggling to overcome. Here's a slice of what I have so far:

Dim polNo
polNo = GetText(10,18,10)

Dim wsh
Set wsh=CreateObject("WScript.Shell")

subSub1_()
sub subSub1_()

// Just doing this to check the text I have
SendKeys(polNo)

// Sent the eMail with the text
wsh.Run "mailto:[email protected]?Subject=" & polNo

end sub

With the above, the resulting email subject line takes only the first word upto the first space. From what I've found, this is a parsing issue & have discovered the following line that should help.

polNo = Chr(34) + Replace(polNo,chr(34),chr(34)&chr(34))

The above line places all of the text in quotes (I know this because my SendKeys line now shows the GetText result with a " at the start.

The issue is when I reach the mailto line as Outlook pops up a window saying:

"The command line argument is not valid. Verify the switch you are using."

My end result will be an email that has a subject & a body with text taken from various parts of the screen.

Solved: Thanks to dmc below, he started me on the right line.

However, the solution was not to use Chr(34) but to use something as simple as:

polNo = Replace(polNo," ","20%")

Upvotes: 1

Views: 252

Answers (1)

dmc
dmc

Reputation: 2684

Although it might not look like it, you're constructing a URL. As such, the contents of that URL must be URL Encoded. Certain characters can't be included in a URL, including a space. Those characters are represented with a percent sign followed by the ASCII code of the character in hexadecimal. For example, a space is changed to %20.

See the link below for a VBScript routine that will URL encode and decode strings. http://www.justskins.com/forums/wsh-equivalent-of-server-38778.html

Edit: Although this is commonly known as URL encoding, the thing you're constructing is technically a URI. Wikipedia has a good page that explains further.

Upvotes: 2

Related Questions