Forum Discussion

DeepaJ's avatar
DeepaJ
Contributor
9 years ago
Solved

Calculate value of variable using parameter default value and an on-scree object variable value

I have a parameter (Invoice Amount), which has a default value of 1000. I have a variable (discount), whose value I get from an on-screen object. I need to calculate the value of Amount (which is another vaiable). I need this value to be stored and entered into the text field of another on-screen object. The calculation is simple - Amount = Invoice Amount - Discount.

I am not sure how to reference parameters and variable in VBScript. I keep getting an error that it is not running the test.

 

I also tried 'Run Code Snippet' with value as

Execute(KeywordTests.MY_Test.Parameters.Invoice_Amount - KeywordTests.MY_Test.Variables.Discount_Amount).

However, it just enters this string as the value into the on-screen, text field instead of the calculated value.

 

Any help or suggestions would be greatly appreciated.

Deepa.

  • See attached screenshots.  I wrote the total into a remarks field that's text so you can see the layout.  If you still aren't seeing the correct calculations, put log messages at the top and display each one of the variables so you can see what the values are at the beginning.

     

     

7 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    If Discount and Amount are project variables, then use:

    Project.Variables.Amount = aqConvert.StrToInt(InvoiceAmount) - aqConvert.StrToInt(Project.Variables.Discount)

     

    If they are local variables, then use:

    Amount = aqConvert.StrToInt(InvoiceAmount) - aqConvert.StrToInt(Discount)

     

    To set the on-screen value, use

    NameOfObjectToSet.set_text(Project.Variables.Amount)

    or

    NameOfObjectToSet.set_text(Amount)

     

    • DeepaJ's avatar
      DeepaJ
      Contributor

      Thanks Marsha.

       

      It still is not giving me the calculated value, and does not enter any value into the field.

      Discount_Amount and Bank_Amount are local variables.

      But, Invoice Amount is a parameter, local to the test.

       

      I have it now as:

      Run Code Snippet                     Bank_Amnt = aqConvert.StrToInt(Invoice_Amount) - aqConvert.StrToInt(Discount_Amount)

      Object           SetText                    KeywordTests.My_Test.Variables.Bank_Amnt (also tried it as just Bank_Amnt)

       

       

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3

        See attached screenshots.  I wrote the total into a remarks field that's text so you can see the layout.  If you still aren't seeing the correct calculations, put log messages at the top and display each one of the variables so you can see what the values are at the beginning.