Forum Discussion

Mrunal's avatar
Mrunal
Contributor
10 years ago

Unable to save Textfile contents into variable value

Hi,




I want to read text from Textfile and want to post it as a value to project suite variable. I want this value to be used in decision making in different projects like whether variable value is equal to filetext.


I am not able to do it by readwhole textfile and open textfile because i am not able to post it to project suite variable. How to store file contents as variable value?

  • Hi Mrunal,



    So, as per Ashok's reply, what is the actual problem? What does not work for you? Can you get the contents of the file? Can you assign it to the project variable? Any problems with the further comparison?

    Note: direct comparison like "(ProjectSuite.Variables.var name == "abc")" may fail if the data read from the file contain characters like carriage return/line feed/etc. These characters must be removed (for example, with the help of the Trim() function) before comparison.
  • Hi Mrunal,



    problem description is not clear. Can you be more descriptive please.



    However by the details i can understrand that you are able to read the contents of a textfile but not able to assign them to a project variable.



    1. If you are not able to read the text file these should help you.

    http://support.smartbear.com/viewarticle/8918/

    http://support.smartbear.com/viewarticle/60211/



    2. If test file is read into a variable then you can assign them as below



    ex:

    var sTextFileContent = aqFile.ReadWholeTextFile("C:\1.txt", aqFile.ctANSI);

    Project.Variables.AddVariable("MyFileContents", eval(sTextFileContent));



    Hope this helps

  • Hi Ashok,

    Thanks for help.



    My scenario:- I am executing bat file which will generate text file and will generate some string in it. I want to use this textfile string and want to store it in project suite variable. My condition will be like if project suite variable equals to abc then execute following steps else execute another.



    I want this variable value to be used across different projects.



    E.g. if(ProjectSuite.Variables.var name == "abc")

              Log.Message("Success", ""); // execute some steps

            else

              Log.Message("Failure", ""); // execute remaining steps


  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Mrunal,



    So, as per Ashok's reply, what is the actual problem? What does not work for you? Can you get the contents of the file? Can you assign it to the project variable? Any problems with the further comparison?

    Note: direct comparison like "(ProjectSuite.Variables.var name == "abc")" may fail if the data read from the file contain characters like carriage return/line feed/etc. These characters must be removed (for example, with the help of the Trim() function) before comparison.

  • Hi Alexei,



    I am now able to read string with help of ReadWhole Text file and able to store it into variable. I can now compare file contents with say "abc".



    Thanks for help.