Discussion:
How to pass parameter from a file (txt/dll) to vbs code
(too old to reply)
LucasYew
2009-05-11 10:22:00 UTC
Permalink
Hi Guys,

Any idea how to pass parameter from a file (txt/dll) to vbs code?

Eg:
txt/.dll file contain value that pass the variable to .vbs file so
that the .vbs file can get the variable to process.
--
LucasYew
------------------------------------------------------------------------
LucasYew's Profile: http://forums.techarena.in/members/76919.htm
View this thread: http://forums.techarena.in/server-scripting/1177796.htm

http://forums.techarena.in
Pegasus [MVP]
2009-05-11 12:55:28 UTC
Permalink
Post by LucasYew
Hi Guys,
Any idea how to pass parameter from a file (txt/dll) to vbs code?
txt/.dll file contain value that pass the variable to .vbs file so
that the .vbs file can get the variable to process.
--
LucasYew
------------------------------------------------------------------------
LucasYew's Profile: http://forums.techarena.in/members/76919.htm
View this thread: http://forums.techarena.in/server-scripting/1177796.htm
http://forums.techarena.in
Neither a .txt nor a .dll file can generate a parameter by itself - both
must to be invoked by some other program. You need to say what program this
is. You also need to clarify if you want to pass the console output
generated by the unknown program to the VB Script file. Are you talking
about a single line of text? Multiple lines?
LucasYew
2009-05-12 05:11:43 UTC
Permalink
Hi Pegasus,
There is a fix value save in .txt/.dll file then the value is pass over
to .vbs file to process because i dont want to make changes for the
value on .vbs code rather then just change the value in other place.
This purpose is to easy to manage the value in future rather the seach
which line in .vbs code to change the value.
--
LucasYew
------------------------------------------------------------------------
LucasYew's Profile: http://forums.techarena.in/members/76919.htm
View this thread: http://forums.techarena.in/server-scripting/1177796.htm

http://forums.techarena.in
Pegasus [MVP]
2009-05-12 05:58:42 UTC
Permalink
Post by LucasYew
Hi Pegasus,
There is a fix value save in .txt/.dll file then the value is pass over
to .vbs file to process because i dont want to make changes for the
value on .vbs code rather then just change the value in other place.
This purpose is to easy to manage the value in future rather the seach
which line in .vbs code to change the value.
--
LucasYew
If your reply is intended to clarify your original question then I am unable
to understand any of it. Sorry.
LucasYew
2009-05-12 06:49:48 UTC
Permalink
Hi Pegasus,
Thanks for your reply.

maybe i give you example to clear the doubt

Eg: .dll file
BATCHFILE=D:\ExchangeField_Extraction\ADExch_Exporting_Field.bat
RCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field.csv
WCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field1.csv


Eg: .vbs file getting the value from .dll file
Dim objFSO, shell
Call getInfo()
set shell=createobject("wscript.shell")
shell.run sbatch
set shell=nothing

Function getInfo()
Dim fso, sbatch, scsv, tstream, sline, sPara,iLen
Set fso = CreateObject("Scripting.FileSystemObject")
Set tstream =
fso.OpenTextFile("D:\ExchangeField_Extraction\pathChanges.dll")

Do Until not tstream.AtEndOfStream
sline = tstream.ReadLine
sPara = "BATCHFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
sbatch = Right(sline, Len(Trim(sline)) - iLen - 1)
WScript.Echo sbatch & "sub"
End If

sPara = "RCSVFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
scsv = Right(sline, Len(Trim(sline)) - iLen - 1)
End If

sPara = "WCSVFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
scsvW = Right(sline, Len(Trim(sline)) - iLen - 1)
End If
Loop
tstream.Close
End Function
--
LucasYew
------------------------------------------------------------------------
LucasYew's Profile: http://forums.techarena.in/members/76919.htm
View this thread: http://forums.techarena.in/server-scripting/1177796.htm

http://forums.techarena.in
Pegasus [MVP]
2009-05-12 07:47:54 UTC
Permalink
Post by LucasYew
Hi Pegasus,
Thanks for your reply.
maybe i give you example to clear the doubt
Eg: .dll file
BATCHFILE=D:\ExchangeField_Extraction\ADExch_Exporting_Field.bat
RCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field.csv
WCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field1.csv
Eg: .vbs file getting the value from .dll file
Dim objFSO, shell
Call getInfo()
set shell=createobject("wscript.shell")
shell.run sbatch
set shell=nothing
Function getInfo()
Dim fso, sbatch, scsv, tstream, sline, sPara,iLen
Set fso = CreateObject("Scripting.FileSystemObject")
Set tstream =
fso.OpenTextFile("D:\ExchangeField_Extraction\pathChanges.dll")
Do Until not tstream.AtEndOfStream
sline = tstream.ReadLine
sPara = "BATCHFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
sbatch = Right(sline, Len(Trim(sline)) - iLen - 1)
WScript.Echo sbatch & "sub"
End If
sPara = "RCSVFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
scsv = Right(sline, Len(Trim(sline)) - iLen - 1)
End If
sPara = "WCSVFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
scsvW = Right(sline, Len(Trim(sline)) - iLen - 1)
End If
Loop
tstream.Close
End Function
I can see a major problem with your script. It processes a .dll file, which
is a binary file, the you use the ReadLine method, which is a text file
method. It will read the current file up to the nearest EndOfLine marker. A
.dll may or may not have any EndOfLine markers and it is certainly not
structured as a collection of lines.

VB Script can be used to extract data from a binary file but not in this
way. What do you actually want to get out of this .dll file?
Richard Mueller [MVP]
2009-05-12 14:58:53 UTC
Permalink
It looks like you ".dll" file is actually a text file, so you can use the
textstream methods to read it. I see a few problems causing the script to
fail. First, you do not Dim scsvW in the function. Second, you Dim sbatch in
the function but not in the main program. This means the value of sbatch is
not visible in the main program. You should NOT Dim sbatch in the function,
and instead Dim sbatch in the main program. This makes it a global variable
visible everywhere.

I would recommend using "Option Explicit" which would make this easier to
troubleshoot. Also, you call your function as if it were a subroutine.
That's OK, it works, but functions generally return a value. You could
design the function to return sbatch, or whatever program should be run.
Having sbatch be a global variable will also work. Finally, when you run the
program it might be better to explicitly call the command processor. For
example:

shell.run "%comspec% /c " & sbatch

However, your version should work as well.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Post by LucasYew
Hi Pegasus,
Thanks for your reply.
maybe i give you example to clear the doubt
Eg: .dll file
BATCHFILE=D:\ExchangeField_Extraction\ADExch_Exporting_Field.bat
RCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field.csv
WCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field1.csv
Eg: .vbs file getting the value from .dll file
Dim objFSO, shell
Call getInfo()
set shell=createobject("wscript.shell")
shell.run sbatch
set shell=nothing
Function getInfo()
Dim fso, sbatch, scsv, tstream, sline, sPara,iLen
Set fso = CreateObject("Scripting.FileSystemObject")
Set tstream =
fso.OpenTextFile("D:\ExchangeField_Extraction\pathChanges.dll")
Do Until not tstream.AtEndOfStream
sline = tstream.ReadLine
sPara = "BATCHFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
sbatch = Right(sline, Len(Trim(sline)) - iLen - 1)
WScript.Echo sbatch & "sub"
End If
sPara = "RCSVFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
scsv = Right(sline, Len(Trim(sline)) - iLen - 1)
End If
sPara = "WCSVFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
scsvW = Right(sline, Len(Trim(sline)) - iLen - 1)
End If
Loop
tstream.Close
End Function
--
LucasYew
------------------------------------------------------------------------
LucasYew's Profile: http://forums.techarena.in/members/76919.htm
View this thread: http://forums.techarena.in/server-scripting/1177796.htm
http://forums.techarena.in
Richard Mueller [MVP]
2009-05-12 15:47:07 UTC
Permalink
I forgot to mention another correction. The following is in error:

Do Until not tstream.AtEndOfStream

It should be:

Do Until tstream.AtEndOfStream

Otherwise the code reads no lines.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Post by Richard Mueller [MVP]
It looks like you ".dll" file is actually a text file, so you can use the
textstream methods to read it. I see a few problems causing the script to
fail. First, you do not Dim scsvW in the function. Second, you Dim sbatch
in the function but not in the main program. This means the value of
sbatch is not visible in the main program. You should NOT Dim sbatch in
the function, and instead Dim sbatch in the main program. This makes it a
global variable visible everywhere.
I would recommend using "Option Explicit" which would make this easier to
troubleshoot. Also, you call your function as if it were a subroutine.
That's OK, it works, but functions generally return a value. You could
design the function to return sbatch, or whatever program should be run.
Having sbatch be a global variable will also work. Finally, when you run
the program it might be better to explicitly call the command processor.
shell.run "%comspec% /c " & sbatch
However, your version should work as well.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Post by LucasYew
Hi Pegasus,
Thanks for your reply.
maybe i give you example to clear the doubt
Eg: .dll file
BATCHFILE=D:\ExchangeField_Extraction\ADExch_Exporting_Field.bat
RCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field.csv
WCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field1.csv
Eg: .vbs file getting the value from .dll file
Dim objFSO, shell
Call getInfo()
set shell=createobject("wscript.shell")
shell.run sbatch
set shell=nothing
Function getInfo()
Dim fso, sbatch, scsv, tstream, sline, sPara,iLen
Set fso = CreateObject("Scripting.FileSystemObject")
Set tstream =
fso.OpenTextFile("D:\ExchangeField_Extraction\pathChanges.dll")
Do Until not tstream.AtEndOfStream
sline = tstream.ReadLine
sPara = "BATCHFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
sbatch = Right(sline, Len(Trim(sline)) - iLen - 1)
WScript.Echo sbatch & "sub"
End If
sPara = "RCSVFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
scsv = Right(sline, Len(Trim(sline)) - iLen - 1)
End If
sPara = "WCSVFILE"
iLen = Len(sPara)
If Left(sline, iLen) = sPara Then
scsvW = Right(sline, Len(Trim(sline)) - iLen - 1)
End If
Loop
tstream.Close
End Function
--
LucasYew
------------------------------------------------------------------------
LucasYew's Profile: http://forums.techarena.in/members/76919.htm
View this thread: http://forums.techarena.in/server-scripting/1177796.htm
http://forums.techarena.in
Pegasus [MVP]
2009-05-12 15:47:47 UTC
Permalink
It looks like you ".dll" file is actually a text file . . .
<snip>
Which crystal ball did you use to come to this conclusion? Can I have a loan
of it to help me determine what posters mean but never quite get around to
spelling out?
Richard Mueller [MVP]
2009-05-12 15:54:46 UTC
Permalink
Post by Pegasus [MVP]
It looks like you ".dll" file is actually a text file . . .
<snip>
Which crystal ball did you use to come to this conclusion? Can I have a
loan of it to help me determine what posters mean but never quite get
around to spelling out?
I could be wrong, but a true dll wouldn't make much sense. These lines in
the posters reply made me decide it was a text file:

Eg: .dll file
BATCHFILE=D:\ExchangeField_Extraction\ADExch_Exporting_Field.bat
RCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field.csv
WCSVFILE=D:\ExchangeField_Extraction\E2K3AD_field1.csv

I think this an example of the "dll" file.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
LucasYew
2009-05-18 09:07:32 UTC
Permalink
Hi Guys,
Thanks for all the response and suggestion especially Richard Mueller.
You understand what i need and finally resolved by your suggestion.
Thanks again and this thread is closed.
--
LucasYew
------------------------------------------------------------------------
LucasYew's Profile: http://forums.techarena.in/members/76919.htm
View this thread: http://forums.techarena.in/server-scripting/1177796.htm

http://forums.techarena.in
Loading...