Home All Groups Group Topic Archive Search About

How to pass parameter from a file (txt/dll) to vbs code

Author
11 May 2009 10:22 AM
LucasYew
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.htmhttp://forums.techarena.in

Author
11 May 2009 12:55 PM
Pegasus [MVP]
Show quote Hide quote
"LucasYew" <LucasYew.3s0r7b@DoNotSpam.com> wrote in message
news:LucasYew.3s0r7b@DoNotSpam.com...
>
> 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

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?
Author
12 May 2009 5:11 AM
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 ------------------------------------------------------------------------ LucasYew's Profile: http://forums.techarena.in/members/76919.htm View this thread: http://forums.techarena.in/server-scripting/1177796.htmhttp://forums.techarena.in
Author
12 May 2009 5:58 AM
Pegasus [MVP]
"LucasYew" <LucasYew.3s257c@DoNotSpam.com> wrote in message
news:LucasYew.3s257c@DoNotSpam.com...
>
> 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.
Author
12 May 2009 6:49 AM
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.htmhttp://forums.techarena.in
Author
12 May 2009 7:47 AM
Pegasus [MVP]
Show quote Hide quote
"LucasYew" <LucasYew.3s2arb@DoNotSpam.com> wrote in message
news:LucasYew.3s2arb@DoNotSpam.com...
>
> 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?
Author
12 May 2009 2:58 PM
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. 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
--

Show quoteHide quote
"LucasYew" <LucasYew.3s2arb@DoNotSpam.com> wrote in message
news:LucasYew.3s2arb@DoNotSpam.com...
>
> 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
>
Author
12 May 2009 3:47 PM
Richard Mueller [MVP]
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
--

Show quoteHide quote
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:eD7evIx0JHA.1432@TK2MSFTNGP02.phx.gbl...
> 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
> --
>
> "LucasYew" <LucasYew.3s2arb@DoNotSpam.com> wrote in message
> news:LucasYew.3s2arb@DoNotSpam.com...
>>
>> 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
>>
>
>
Author
12 May 2009 3:47 PM
Pegasus [MVP]
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:eD7evIx0JHA.1432@TK2MSFTNGP02.phx.gbl...
> 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?
Author
12 May 2009 3:54 PM
Richard Mueller [MVP]
"Pegasus [MVP]" <n***@microsoft.com> wrote in message
news:uPg5Akx0JHA.2300@TK2MSFTNGP06.phx.gbl...
>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:eD7evIx0JHA.1432@TK2MSFTNGP02.phx.gbl...
>> 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
--
Author
18 May 2009 9:07 AM
LucasYew
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.htmhttp://forums.techarena.in