Passing variable to vbscripts

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mikelottridge
Newbie
Posts: 2
Joined: Sat Oct 15, 2005 6:37 pm

Passing variable to vbscripts

Post by mikelottridge » Sat Oct 15, 2005 6:42 pm

Just getting starting and have a basic question - how can I pass a variable to a vbscript? In this case, I'm reading a file into a variable and then want to send the contents using Lotus notes. This syntax gives me an invalid character error in the Vbscript where I reference %msg%. If I put %msg% in quotes ("%msg%" ) I just get the string %msg% in the email.

ReadFile>c:\temp\tmp.txt,msg
Message>%msg%

VBSTART

Sub SendNotesMail
Set nSession = CreateObject("Notes.NotesSession")
'Gets the current user's maildatabase
Set db = nSession.GETDATABASE("","")
Call db.OPENMAIL
Set doc = db.CREATEDOCUMENT
Call doc.REPLACEITEMVALUE("SendTo", "[email protected]")
Call doc.REPLACEITEMVALUE("Subject", "Mail sent from VBscript using Lotus Notes")
Call doc.REPLACEITEMVALUE("Body", %msg%)
Call doc.SEND(False)
End Sub

VBEND
VBRun>SendNotesMail

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Sun Oct 16, 2005 3:28 pm

I prefer to put my VBS code at the top of the script. Pass the variable into the subroutine by setting it as a subroutine parameter and pass it on the VBRun line.

VBSTART
Sub SendNotesMail(msg)
Set nSession = CreateObject("Notes.NotesSession")
'Gets the current user's maildatabase
Set db = nSession.GETDATABASE("","")
Call db.OPENMAIL
Set doc = db.CREATEDOCUMENT
Call doc.REPLACEITEMVALUE("SendTo", "[email protected]")
Call doc.REPLACEITEMVALUE("Subject", "Mail sent from VBscript using Lotus Notes")
Call doc.REPLACEITEMVALUE("Body", msg)
Call doc.SEND(False)
End Sub
VBEND

ReadFile>c:\temp\tmp.txt,msg
Message>%msg%

VBRun>SendNotesMail,msg
MJT Net Support
[email protected]

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts