Joe
Mon Jan 19 15:41:29 CST 2004
Hi again,
"Houman Yahyaei" <news@formationhy.com> wrote in message
news:OmT0yrr3DHA.2460@TK2MSFTNGP10.phx.gbl...
| Could you explain a bit more number 2 and 4...
|
| They both seem interesting...
|
| Thanks !!!
|
| --
| --
| Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
| IT Training and Consulting
| www.formationhy.com
| Houman@formationhy.com
|
| "Joe Earnest" <joeearnestNO@SPAMqwest.netPLEASE> wrote in message
| news:%23alhQKq3DHA.3360@tk2msftngp13.phx.gbl...
| > Hi,
| >
| > "Houman Yahyaei" <news@formationhy.com> wrote in message
| > news:#MQPO$p3DHA.1704@tk2msftngp13.phx.gbl...
| > | Hi...
| > | I posted this before, but probably didn't explain my self well...
| > |
| > | I need to have a script that declares and sets a value for some vb
| > | variables, and want to have the value in these variables available in
| > other
| > | script...
| > |
| > | Here is what I do :
| > | I have a master script that calls other scripts...
| > | 1st script called from master script, it declares and sets values for
| some
| > | variables ...
| > | ex : Public appver1
| > | appver1 = "V9_4_2"
| > |
| > | 2nd script called from master script would use the variables set in
1st
| > | script to do execute actions with it...
| > | ex : WshEnv("Var1") = appver1
| > |
| > | How can this be done ...
| > | The value is "appver1" is not necessary outside of the vb
environment...
| > | Reason is that 1st script will be modified by a lot of people, but
don't
| > | want them to modify other script...
| > |
| > | Thanks very much !!!
| > |
| > | --
| > | --
| > | Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
| > | IT Training and Consulting
| > | www.formationhy.com
| > | Houman@formationhy.com
| >
| > As a script, VBS has no ability to create data sinks, as such. There
are
| > four basic methods to pass data among separate scripts:
| >
| > 1) Primary/secondary scripts run other scripts with data arguments
and/or
| > get limited return through the Quit long integer code.
| >
| > 2) Primary/secondary scripts create session environmental variable(s)
| that
| > can be accessed from other scripts.
| >
| > 3) Primary/secondary scripts create temporary file(s) that can be
| accessed
| > from other scripts.
| >
| > 4) Michael Harris' IePipe solution:
| > Primary script creates an Ie.App window which does not have to be set as
| > visible. It can contain both data variables and embedded routines for
the
| > secondary scripts. Secondary scripts get Ie.App object instance through
| the
| > ShellApp.Windows object collection and use the nominal window as a
| singleton
| > object instance to pass data back and forth through variables or run
| common
| > routines.
| >
| > Joe Earnest
Torgeir Bakken explained #2 in his response to your first post, though you
may not have understood the context. (Torgeir's earlier response inline.)
---
Hi
As long as the main script is the one that starts the other scripts, using
the
process environment will work. Create the two scripts below and run the main
script to see this (if you change the name/path of C:\SecondScript.vbs,
update
the main script's Run statement accordingly).
-------------------- Main script --------------------
Set Wshshell = CreateObject("WScript.Shell")
Set oProcessEnv = Wshshell.Environment("PROCESS")
Appvar1 = "abcxyz"
oProcessEnv("NameApp1") = Appvar1
Wshshell.Run "wscript.exe C:\SecondScript.vbs", 1, False
---------------- C:\SecondScript.vbs ----------------
Set Wshshell = CreateObject("WScript.Shell")
MsgBox "Content off NameApp1 (variant 1): " _
& Wshshell.ExpandEnvironmentStrings("%NameApp1%")
Set oProcessEnv = Wshshell.Environment("PROCESS")
MsgBox "Content off NameApp1 (variant 2): " & oProcessEnv("NameApp1")
---
For #4, take a look the thread with Michael Harris' original post:
http://www.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&newwindow=1&safe=off&th=819e016807d6b05&rnum=8
and subsequent threads (a Google advanced group search on "iepipe"):
http://www.google.com/groups?q=iepipe+group:microsoft.public.scripting.*&hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&newwindow=1&safe=off&start=0&sa=N
The script creating the first window is in MH's original post some of the
followups. The following adds a "DimNew" function that allows any script to
create a new variable or redimension an existing array, for storage in the
IE window. You don't need that function, if you define all the variables
needed in your initial dim statement. If you do want it, an explanation of
the syntax follows the code:
---
set oIe= createobject("internetExplorer.application")
oIe.navigate("about:blank")
do: wscript.sleep 50: loop until (oIe.readyState=4)
with oIe.document
.writeLn ("<html>")
.writeLn ("<head>")
.writeLn ("<script language=""vbscript"">")
.writeLn ("dim ...")
' the following is the DimNew code
.writeLn ( _
_
"function DimNew (byval vsVars)" & vbCrLf _
& "dim viVar, vpClose, vpOpen" & vbCrLf _
& "if NOT (vartype(vsVars)=vbString) then exit function" _
& vbCrLf _
& "vsVars= replace(replace(replace(vsVars, "" "", """"), _
"";"", "",""), "":"", "","")" & vbCrLf _
& "vpOpen= instr(vsVars, ""("")" & vbCrLf _
& "do while vpOpen" & vbCrLf _
& "vpClose= instr(vpOpen +1, vsVars, "")""): _
if (vpClose=0) then exit do" & vbCrLf _
& "vsVars= left(vsVars, vpOpen -1) " _
& "& replace(mid(vsVars, vpOpen, vpClose -vpOpen +1), " _
& ""","", ""|"") & mid(vsVars, vpClose +1)" & vbCrLf _
& "vpOpen= instr(vpOpen +1, vsVars, ""("")" & vbCrLf _
& "loop: vsVars= split("","" & vsVars, "","")" & vbCrLf _
& "for viVar= 1 to ubound(vsVars)" & vbCrLf _
& "on error resume next" & vbCrLf _
& "select case instr(vsVars(viVar), ""("")" & vbCrLf _
& "case 0: execute vsVars(viVar) & ""= empty""" & vbCrLf _
& "case else: vsVars(viVar)= replace(vsVars(viVar), ""|"", "","")" _
& vbCrLf _
& "execute ""redim preserve "" & vsVars(viVar)" & vbCrLf _
& "if err then err clear: execute ""redim "" & vsVars(viVar)" _
& vbCrLf _
& "end select" & vbCrLf _
& "on error goto 0" & vbCrLf _
& "next" & vbCrLf _
& "end function")
' remainder of required code
.writeLn ("...") 'your routines
.writeLn ("</script>")
.writeLn ("</head>")
.writeLn ("</html>")
end with
---
If used, the DimNew function allows new variables or dynamic arrays to be
declared, or dynamic arrays redimensioned, in the IeApp object window script
element, using the intrinsic execute statement to create new embedded HTML
global variables. The new or redimensioned variables may then be accessed
by any of the multiple scripts that use the dialog window. The syntax of
the embedded HTML DimNew function is similar to that of the intrinsic dim
statement. A single variable name or a variable list may be used. A
variable list may be delimited by commas (,), semi-colons (;) or colons (:).
Even though arrays are declared dynamically, the specific dimensions and
element upper bounds must be provided, as if declaring a static array with a
traditional dim statement. With array variables, the function will first
try to redim preserve the variable, to allow modification of the number of
elements in the final dimension. If that fails (e.g., for new variables,
dimensional changes, or non-final dimension element bound changes), then the
array will be dynamically redimensioned using redim, and any existing data
will be lost. The function provides no return. The format is:
set oScript= oIE.document.parentWindow.document.script
oScript.dimNew variable[(...)][, ...]
An example of code used in the secondary script file is the following:
---
' insert lcased <<title>> used creating IE window
set oShell= createObject("shell.application")
set oWins= oShell.windows
on error resume next
for each oWin in oWins
do
qIe= cbool(instr(lcase(typename _
(oWin.document)), "htmldocument"))
if err then exit do
if qIe then
sTitle= trim(oWin.document.title)
if err then exit do
if (lcase(sTitle)="<<title>>") then
set oIe= oWin
exit for
end if
end if
loop until true: err.clear
next
on error goto 0
with oIe.document.parentWindow.document.script
xWshVariable= .xHtmlVariable
.xHtmlVariable= value
[return=] .HtmlFunction [(arguments)]
end with
---
There may be scoping issues if trying to pass object variables, but these
issues do not arise with simple data variables. Be sure to close the IE
window when the last script is closed or when it is no longer needed
(oIe.quit).
Joe Earnest
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 09-23-03