Forum Discussion

tim_espasandin's avatar
tim_espasandin
Occasional Contributor
12 years ago

Concatenating objects with strings

I'm trying to use Javascript to modify the object that a variable points to by adding a string to the variable. However, this simply gives me an undefinded variable. Is there some way for me to achieve this?



Here's an example of what I'm trying to do:




function ConcatProblem()


{


  var notepad, window, finished;


  notepad = Sys.Process("notepad");


  window = ".Window(\"Notepad\", \"Untitled - Notepad\", 1).Window(\"Edit\", \"\", 1)";


  finished = notepad + window;


  finished.wtext = "Text here";


}



Edit: Corrected string.

  • tim_espasandin's avatar
    tim_espasandin
    Occasional Contributor
    If this isn't possible, can anyone tell me an alternate way to accomplish my goal?



    I'm working with a file that contains text strings that indicate where a bunch of objects should be, in relation to a specific object which I am able to locate using the Find method. I was hoping that I could check for the object by adding the string to the object that I've found, but that doesn't seem to be working. Can anyone tell me a better way to find the objects that I'm looking for?
  • tim_espasandin's avatar
    tim_espasandin
    Occasional Contributor
    Here's a thought...



    Isn't an object's FullName property a string? Maybe I could do something like:



    notepad = Sys.Process("notepad").Fullname;



    That should give me a string that I can work with normally. I'll give it a try.
  • tim_espasandin's avatar
    tim_espasandin
    Occasional Contributor
    Here's what I wound up with.




    function ConcatProblem()


    {


      var notepad, window, finished, finalvariable;


      notepad = Sys.Process("notepad").FullName;


      window = ".Window(\"Notepad\", \"Untitled - Notepad\", 1).Window(\"Edit\", \"\", 1)";


      finished = notepad + window;


      finalvariable = Sys.Find("FullName", finished, 100);


      finalvariable.wtext = "Text here";


    }



    This seems to work just fine. If anyone has a better way to do this, please let me know.


  • Hi Tim,


     


    You can use the eval function instead of searching the target object (this might slow down the test execution): 


    function test()


    {


      var notepad, window, finished;


      notepad = Sys.Process("notepad").FullName;


      window = ".Window(\"Notepad\", \"Untitled - Notepad\", 1).Window(\"Edit\", \"\", 1)";


      finished = notepad + window;


      eval(finished).wText = "new text";


    }