Windows Vista Forums

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


    Larry Guest

    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

  2. #2


    Pegasus [MVP] Guest

    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

    >
    >
    > 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:

    > 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

  3. #3


    Larry Guest

    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

  4. #4


    Pegasus [MVP] Guest

    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

    >
    > 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

  5. #5


    Al Dunbar Guest

    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

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

    >>
    >> 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

  6. #6


    Larry Guest

    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

    > 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

  7. #7


    Larry Guest

    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:

    > 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.
    Ok, how do I write sText into a temp file, and how do I retrieve it?

    Thanks,
    Larry


      My System SpecsSystem Spec

  8. #8


    Pegasus [MVP] Guest

    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

    > You write:
    >

    >> 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.
    >
    > 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

  9. #9


    Al Dunbar Guest

    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

    >> 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.

    > 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

  10. #10


    Larry Guest

    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

Page 1 of 3 123 LastLast
Grabbing a string that's already been created in one .vbs file and doing stuff with it in a second .vbs file problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Solved Used Alt 0160 - And Now I can't Delete File Created - PLEASE HELP! NYC General Discussion 4 16 May 2012
How to get teh recentest created file in a folder Joshwa VB Script 4 05 May 2009
Cannot view file date created Bill Burton Vista file management 2 18 Feb 2008
Grabbing a number after the Nth occurence of something within a single string Marco Shaw PowerShell 7 23 Oct 2006
create dir, stuff some logs in a new file in that dir =?Utf-8?B?R2lsIE5vdmFr?= PowerShell 3 12 Sep 2006