Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript and Paramaeter Lists

Status
Not open for further replies.

thomasgk

Programmer
Jul 6, 2003
1
US
I am trying to convert a huge bat file to a vbs file. However currently we pass the .bat file a parameter list that just sets a huge list of variables. It has to be done this way because there is a huge list of variable for each of our clients.

There is no include in VBScript but does anyone know of a way I can call a txt or vbs file from my vbs script and inside the file I call will just be a list of variables and there values.

I appreciate any help.
 
Actually, while VBScript has no "include" functionality WSH certainly does!

Instead of writing the oldest form of WSH script, the .js or .vbs file, you make a .wsf (Windows Script File) instead. This has been around since about WSH 2.0 I think.

sample.wsf
Code:
<job>
<script language="VBScript" src="mystuff.inc"/>
<script language="VBScript">
Option Explicit
MsgBox kstrIncluded
MsgBox CStr(f(34.7))
MsgBox CStr(d)
</script>
</job>
mystuff.inc
Code:
Option Explicit
Const kstrIncluded = "Hello World"
Function f(ByVal x)
  f = 2 * x
End Function
Dim a,b,c,d
a = 1
b = 2.2
c = "testing"
d = #17 Jun 2004#
As you can see, the first script block in sequence (within the <job>) is run first. This gives you a choice of setting up Consts or Dimensioning variables and then setting them.

This is run like any other WSH script, via cscript or wscript at your option as usual.

Those .wsf files offer a lot of other goodies as well.
 
Hello thomasgk,

You can consider a workaround like this, at the last resort.

Construct the txt file with the contents set like this.
Code:
n1=123
n2=456
s1="abc"
s2="def"
In the main, using fso to read the text file line-by-line. Then establish the variable.
Code:
do while not otextstream.atendofstream
    s=otextstream.readline
    if trim(s)<>"" then execute trim(s)
loop
Here you establish successively variable n1, n2,... and s1, s2,... with initialization done as well.

In this scheme, you do not use "option explicit" directive. If you use it, you have either have to prepare the text file with the structure like:
[tt]
dim n1 : n1=123
etc[/tt]
or, you parse the left-hand-size and declare it in the loop before assigning it a value.

If you do it within a sub and worry about the scope of the variable, you can use "executeglobal" instead of "execute".

regards - tsuji
 
if trim(s)<>"" then execute trim(s)
Be aware that this instruction is potentially extremly dangerous if you naively trust the contents of s.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top