Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: How to pass parameter from a file (txt/dll) to vbs code

Reply
Thread Tools Display Modes

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

 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      05-11-2009

"LucasYew" <> wrote in message
news:...
>
> 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?


 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      05-12-2009

"LucasYew" <> wrote in message
news:...
>
> 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.


 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      05-12-2009

"LucasYew" <> wrote in message
news:...
>
> Hi Pegasus,
> Thanks for your reply.
>
> maybe i give you example to clear the doubt
>
> Eg: .dll file
> BATCHFILE=D:\ExchangeField_Extraction\ADExch_Expor ting_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\path Changes.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?


 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      05-12-2009
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" <> wrote in message
news:...
>
> Hi Pegasus,
> Thanks for your reply.
>
> maybe i give you example to clear the doubt
>
> Eg: .dll file
> BATCHFILE=D:\ExchangeField_Extraction\ADExch_Expor ting_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\path Changes.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
>



 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      05-12-2009
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
--

"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:...
> 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" <> wrote in message
> news:...
>>
>> Hi Pegasus,
>> Thanks for your reply.
>>
>> maybe i give you example to clear the doubt
>>
>> Eg: .dll file
>> BATCHFILE=D:\ExchangeField_Extraction\ADExch_Expor ting_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\path Changes.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
>>

>
>



 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      05-12-2009

"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:...
> 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?


 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      05-12-2009

"Pegasus [MVP]" <> wrote in message
news:...
>
> "Richard Mueller [MVP]" <rlmueller-> wrote in
> message news:...
>> 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_Expor ting_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
--


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How can I pass a parameter to the URL? rob^_^ Internet Explorer 0 10-22-2008 08:23 AM
Re: Pass a comma as an unquoted parameter to a batch script in the windows CMD Pegasus \(MVP\) Scripting 1 04-29-2008 02:31 AM
[PSH] How do you pass ranges (1..10) as a parameter? Keith Hill [MVP] Scripting 3 05-17-2006 04:00 PM
[MSH] How to pass parameter and its value to a cmdlet Dung K Hoang Scripting 3 04-04-2006 11:33 PM
How to pass the parameter while creating the user in AD ? uday Scripting 1 04-04-2005 04:45 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59