Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file

Reply
 
Old 06-07-2009   #1 (permalink)
Larry


 
 

Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file



First, I've created a string using a .vbs file, like this:

'make string out of clipboard contents
sText = oHtml.parentwindow.clipboardData.getData("text")

Then I've done stuff in other applications.

Now I want to grab the string I created and transfer it to the Clipboard
so as to paste it into an application, like this:

' Paste sText into document
Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
oAutoIt.ClipPut(sText)
oShell.SendKeys"^v"

Question: how do I grab sText that's already been created in one .vbs file,
and run a second .vbs file that puts the string in the Clipboard and pastes
it?

Thanks,
Larry


My System SpecsSystem Spec
Old 06-07-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file


"Larry" <larry328NOSPAM@xxxxxx> wrote in message
news:OSkGs215JHA.1716@xxxxxx
Quote:

>
>
> First, I've created a string using a .vbs file, like this:
>
> 'make string out of clipboard contents
> sText = oHtml.parentwindow.clipboardData.getData("text")
>
> Then I've done stuff in other applications.
>
> Now I want to grab the string I created and transfer it to the Clipboard
> so as to paste it into an application, like this:
>
> ' Paste sText into document
> Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
> oAutoIt.ClipPut(sText)
> oShell.SendKeys"^v"
>
> Question: how do I grab sText that's already been created in one .vbs
> file,
> and run a second .vbs file that puts the string in the Clipboard and
> pastes
> it?
>
> Thanks,
> Larry
I don't quite understand this paragraph from your post:
Quote:

> Question: how do I grab sText that's already been created in one .vbs
> file,
> and run a second .vbs file that puts the string in the Clipboard and
> pastes
but here are two possible answers:
- To put a string into the clipboard, check this link:
http://www.microsoft.com/technet/scr...4/hey0813.mspx
- To make a string from one script available to another script: Write it to
a temp file, then read it from there. Alternatively, if Script 2 is invoked
from Script 1, pass the string as a parameter surrounded by double quotes.


My System SpecsSystem Spec
Old 06-07-2009   #3 (permalink)
Larry


 
 

Re: Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file


The script you've linked me to, by which a string is transferred to the
Clipboard, won't help me. I already know how to put a string in the
Clipboard, and in fact, my first .vbs file begins with the desired text
already in the clipboard, and I make it into a string.

Here's the idea. I have text in the clipboard, which I'm planning to paste
somewhere. But then I realize that before I can paste it, I've got to copy
something else to the clipboard. I don't want to have the initial text wiped
out before I've had the chance to paste it, so I make it into a string for
the interim. Then, after I've done the other operation which has put other
text in the clipboard, I want to retrieve the string I created, and turn it
back into Clipboard contents so that I can paste it.

The problem is that by the time I get to that last step, the .vbs file where
the string was created is no longer running since I have switched to a
different application where I was performing other tasks. Therefore the
retrieval of the string must be done from a second .vbs file. So my
question is, having created a string in .vbs file 1, how do I then retrieve
that string using .vbs file 2?

To sum up:

1. In .vbs file 1, Clipboard contents is made into string sText.

2. Then I do other stuff in another application, involving putting some
other contents into Clipboard.

3. (This is the part I need help with.) Now I want to run .vbs file 2, with
which I retrieve sText from .vbs file 1, and turn it into Clipboard contents
so that I can paste it.

My System SpecsSystem Spec
Old 06-07-2009   #4 (permalink)
Pegasus [MVP]


 
 

Re: Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file


"Larry" <larry328NOSPAM@xxxxxx> wrote in message
news:OAbxYr45JHA.480@xxxxxx
Quote:

>
> The script you've linked me to, by which a string is transferred to the
> Clipboard, won't help me. I already know how to put a string in the
> Clipboard, and in fact, my first .vbs file begins with the desired text
> already in the clipboard, and I make it into a string.
>
> Here's the idea. I have text in the clipboard, which I'm planning to paste
> somewhere. But then I realize that before I can paste it, I've got to copy
> something else to the clipboard. I don't want to have the initial text
> wiped
> out before I've had the chance to paste it, so I make it into a string
> for
> the interim. Then, after I've done the other operation which has put other
> text in the clipboard, I want to retrieve the string I created, and turn
> it
> back into Clipboard contents so that I can paste it.
>
> The problem is that by the time I get to that last step, the .vbs file
> where
> the string was created is no longer running since I have switched to a
> different application where I was performing other tasks. Therefore the
> retrieval of the string must be done from a second .vbs file. So my
> question is, having created a string in .vbs file 1, how do I then
> retrieve
> that string using .vbs file 2?
>
> To sum up:
>
> 1. In .vbs file 1, Clipboard contents is made into string sText.
>
> 2. Then I do other stuff in another application, involving putting some
> other contents into Clipboard.
>
> 3. (This is the part I need help with.) Now I want to run .vbs file 2,
> with
> which I retrieve sText from .vbs file 1, and turn it into Clipboard
> contents
> so that I can paste it.
Your explanation makes it a lot clearer. Using the steps you posted, here is
a simple solution:

1. In .vbs file 1, Clipboard contents is made into string sText, then write
sText into a temp file.

2. Then I do other stuff in another application, involving putting some
other contents into Clipboard.

3. Run vbs file 2 to retrieve sText from the temp file and to turn it into
Clipboard
contents so that I can paste it.


My System SpecsSystem Spec
Old 06-07-2009   #5 (permalink)
Al Dunbar


 
 

Re: Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file


"Pegasus [MVP]" <news@xxxxxx> wrote in message
news:#6PLQz45JHA.6004@xxxxxx
Quote:

>
> "Larry" <larry328NOSPAM@xxxxxx> wrote in message
> news:OAbxYr45JHA.480@xxxxxx
Quote:

>>
>> The script you've linked me to, by which a string is transferred to the
>> Clipboard, won't help me. I already know how to put a string in the
>> Clipboard, and in fact, my first .vbs file begins with the desired text
>> already in the clipboard, and I make it into a string.
>>
>> Here's the idea. I have text in the clipboard, which I'm planning to
>> paste
>> somewhere. But then I realize that before I can paste it, I've got to
>> copy
>> something else to the clipboard. I don't want to have the initial text
>> wiped
>> out before I've had the chance to paste it, so I make it into a string
>> for
>> the interim. Then, after I've done the other operation which has put
>> other
>> text in the clipboard, I want to retrieve the string I created, and turn
>> it
>> back into Clipboard contents so that I can paste it.
>>
>> The problem is that by the time I get to that last step, the .vbs file
>> where
>> the string was created is no longer running since I have switched to a
>> different application where I was performing other tasks. Therefore the
>> retrieval of the string must be done from a second .vbs file. So my
>> question is, having created a string in .vbs file 1, how do I then
>> retrieve
>> that string using .vbs file 2?
>>
>> To sum up:
>>
>> 1. In .vbs file 1, Clipboard contents is made into string sText.
>>
>> 2. Then I do other stuff in another application, involving putting some
>> other contents into Clipboard.
>>
>> 3. (This is the part I need help with.) Now I want to run .vbs file 2,
>> with
>> which I retrieve sText from .vbs file 1, and turn it into Clipboard
>> contents
>> so that I can paste it.
>
> Your explanation makes it a lot clearer. Using the steps you posted, here
> is a simple solution:
>
> 1. In .vbs file 1, Clipboard contents is made into string sText, then
> write
> sText into a temp file.
>
> 2. Then I do other stuff in another application, involving putting some
> other contents into Clipboard.
>
> 3. Run vbs file 2 to retrieve sText from the temp file and to turn it into
> Clipboard
> contents so that I can paste it.
The short answer, which the OP has by now come to realize, is that
variables, even global ones, go out scope when the script terminates.

/Al


My System SpecsSystem Spec
Old 06-07-2009   #6 (permalink)
Larry


 
 

Re: Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file

> The short answer, which the OP has by now come to realize, is that
Quote:

> variables, even global ones, go out scope when the script terminates.
>
That's what I figured, but I wondered if there was some way around it.

In Word VBA, you can define variables and put them in a macro where they are
permanentely accessible. (I haven't done it in a while, I forget the correct
terms for this.)

Larry

My System SpecsSystem Spec
Old 06-07-2009   #7 (permalink)
Larry


 
 

Re: Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file

You write:
Quote:

> Your explanation makes it a lot clearer. Using the steps you posted, here
is
Quote:

> a simple solution:
>
> 1. In .vbs file 1, Clipboard contents is made into string sText, then
write
Quote:

> sText into a temp file.
>
> 2. Then I do other stuff in another application, involving putting some
> other contents into Clipboard.
>
> 3. Run vbs file 2 to retrieve sText from the temp file and to turn it into
> Clipboard
> contents so that I can paste it.
Ok, how do I write sText into a temp file, and how do I retrieve it?

Thanks,
Larry

My System SpecsSystem Spec
Old 06-07-2009   #8 (permalink)
Pegasus [MVP]


 
 

Re: Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file


"Larry" <larry328NOSPAM@xxxxxx> wrote in message
news:%23geGCp75JHA.1372@xxxxxx
Quote:

> You write:
>
Quote:

>> Your explanation makes it a lot clearer. Using the steps you posted, here
> is
Quote:

>> a simple solution:
>>
>> 1. In .vbs file 1, Clipboard contents is made into string sText, then
> write
Quote:

>> sText into a temp file.
>>
>> 2. Then I do other stuff in another application, involving putting some
>> other contents into Clipboard.
>>
>> 3. Run vbs file 2 to retrieve sText from the temp file and to turn it
>> into
>> Clipboard
>> contents so that I can paste it.
>
> Ok, how do I write sText into a temp file, and how do I retrieve it?
>
> Thanks,
> Larry
Download the help file script56.chm and look at the CreateTextFile and the
WriteLine methods of the File System Object. The help file includes complete
examples for both methods. And for reading, it's the ReadLine method!


My System SpecsSystem Spec
Old 06-07-2009   #9 (permalink)
Al Dunbar


 
 

Re: Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file


"Larry" <larry328NOSPAM@xxxxxx> wrote in message
news:#JHoBp75JHA.1372@xxxxxx
Quote:
Quote:

>> The short answer, which the OP has by now come to realize, is that
>> variables, even global ones, go out scope when the script terminates.
>>
>
> That's what I figured, but I wondered if there was some way around it.
No way "around" it other than work-"around"s like Pegasus' suggestion.
Quote:

> In Word VBA, you can define variables and put them in a macro where they
> are
> permanentely accessible. (I haven't done it in a while, I forget the
> correct
> terms for this.)
Those variables are not stored in or managed by VBA so much as they are
maintained by the program that is the "scripting engine", WinWord.exe.
Wscript.exe and cscript.exe are much leaner scripting engines, as they do
nothing but support a couple of scripting languages, whereas WinWord does at
least a couple of other things.

/Al


My System SpecsSystem Spec
Old 06-07-2009   #10 (permalink)
Larry


 
 

Re: Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file

> Download the help file script56.chm and look at the CreateTextFile and
the
WriteLine methods of the File System Object. The help file includes complete
examples for both methods. And for reading, it's the ReadLine method!

Isn't there an online resource that gives all the info on VBScript? I seem
to remember there used to be one, but I haven't looked it up in a while.

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Solved Used Alt 0160 - And Now I can't Delete File Created - PLEASE HELP! General Discussion
How to get teh recentest created file in a folder VB Script
Cannot view file date created Vista file management
Grabbing a number after the Nth occurence of something within a single string PowerShell
create dir, stuff some logs in a new file in that dir PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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