PDA

View Full Version : Pass a variable to a vbs script and execute it


Gary Williams
10-21-2005, 11:55 AM
Hi All,

I have a vbs script that (thanks to NancyJ) actually works. The script, when run on the server, creates 3 asp files, stores them in a subdirectory and sends an email to my customer. The variable (cusref) is hardcoded in the vbs script at present. So far, so good.

Now, I want to place a simple form (like below) on my web site into which I can enter the 4 digit cusref and when I hit submit, the vbs script is executed using the cusref just entered.

How do I pass (parse?) the variable cusref to the vbs script and cause the vbs script to execute?

Regards

Gary

-----------------------------------

<form name="cusfiles" method="get" action="../CreateCUSfiles.vbs">
Customer Reference <input type="text" value="">
<input type="submit" value="Create Files">
</form>

NancyJ
10-21-2005, 12:36 PM
replace the hard coded cusref value with
request.form("cusref")
and change your form to

<form name="cusfiles" method="get" action="../CreateCUSfiles.vbs">
Customer Reference <input type="text" name = "cusref">
<input type="submit" value="Create Files">
</form>

Gary Williams
10-21-2005, 01:24 PM
Hi Nancy,

OK, tried that.

First I got an alert re open or save the file (chose open) then an alert re publisher (chose run) then got a WSH error message re "Object required: 'request' " (code 800A01A8) for this line of code:

strcusref = request.form("cusref")

Regards

Gary

Roelf
10-21-2005, 01:52 PM
that is because the environment where the vb script is running, doesn't know the Request object.

A vbs does know the WScript object, normally whenever you run a vbscript, commandline arguments are separated from the vbs command by a space, then you can get access to them using:
Set oArgs = WScript.Arguments
If oArgs.Count > 0 then
' do your handling
' access the arguments by oArgs(0) etc.
else
' no commandline arguments found
end if
dont know if the arguments are appended to the vbs call by the form's action, but worth a try

Gary Williams
10-21-2005, 03:51 PM
Hi Roelf,

Now that hurts my brain. Does this mean that to run the script from the command line directly on the server and pass the variable, I should type in "C:/path to script/createcusfiles.vbs cusref(return).

Then use strcusref = oArgs0?

I'm at pre-novice level with this vbs stuff, sorry.

Regards

Gary

NancyJ
10-21-2005, 04:06 PM
Something to consider - does it need to be a vbs file? Is there something about it that cant be handled in asp - you said it creates 3 files and emails a customer - all of which can be done in asp.

Gary Williams
10-21-2005, 05:44 PM
Hi Nancy,

No, it doesn't. I developed what I needed from an original vbs tutorial but had trouble translating it from vbs to asp, hence today's posts. Now that TheShaner has got the % and > treated as text, I may be able to convert to asp and then use the request.form method to pass the customer reference to the new scripts.

Regards

Gary