Forum Discussion

sdekosky1's avatar
sdekosky1
Occasional Contributor
13 years ago

Cannot Find Object using variable in WPFObject





I am attempting to find a WPFObject using the propery "Name". For the value of the property "Name" I want to parameterize WndCaption string using a variable so that I can find certain data in a WPF Grid. The following code will not find the contents of the variable BlockID. Other than using wild cards any other thoughts?



Thanks in Advance

Steve Dekosky


function



FindSpecBlockID()





{





  var PropArray = new Array(1);





  var ValuesArray = new Array(1);





  var BlockID = "B98582";







  PropArray[0] = "Name";





  ValuesArray[0] =  'WPFObject("TextBlock", BlockID, 1)';





                    





  return GofindObject(PropArray,ValuesArray);





}

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Change the following line



    ValuesArray[0] =  'WPFObject("TextBlock", BlockID, 1)';




    to



    ValuesArray[0] =  'WPFObject("TextBlock",' +  BlockID + ', 1)';




    Otherwise, BlockID is simply seen as part of the overall string rather than being a variable that you are concatenating into the string.
  • sdekosky1's avatar
    sdekosky1
    Occasional Contributor


    Hi, This changed worked to allow the contents of the variable to be passed. Thanks Much but one more question on adding double quotes to the string:



    ValuesArray[0] = 'WPFObject("TextBlock",' + BlockID + ', 1)';



    However, the name is being passed as WPFObject("TextBlock", B109281, 1) as opposed to WPFObject("TextBlock", "B109281", 1). The double quotes are being removed from the string causing the object to not be recognized. Thoughts? 

  • sdekosky1's avatar
    sdekosky1
    Occasional Contributor


    Hi, This changed worked to allow the contents of the variable to be passed. Thanks Much but one more question on adding double quotes to the string:



    ValuesArray[0] = 'WPFObject("TextBlock",' + BlockID + ', 1)';



    However, the name is being passed as WPFObject("TextBlock", B109281, 1) as opposed to WPFObject("TextBlock", "B109281", 1). The double quotes are being removed from the string causing the object to not be recognized. Thoughts? 

  • sdekosky1's avatar
    sdekosky1
    Occasional Contributor
    Figured out the issue. Set the variable as follows and now the object Name is recognized!

    var BlockID = ' "B109281" ';


    function



    FindSpecBlockID()





    {





      var PropArray = new Array(1);


      var ValuesArray = new Array(1);


      var BlockID = ' "B109281" ';


      PropArray[0] = "Name";


      ValuesArray[0] =  'WPFObject("TextBlock",' +  BlockID + ', 1)';


      return GofindObject(PropArray,ValuesArray);





    }