Micro Focus QTP (UFT) Forums
Problem With conversion function - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Problem With conversion function (/Thread-Problem-With-conversion-function)



Problem With conversion function - wajid - 09-23-2018

Hi, all 

I am  Wajid from USA and new to UFT. I have some problem with my script.

I have written script where I can compare Estimated and actual cost and print Pass or fail result.

My estimated amount is 15700 that changes with every iteration but my actual cost is in currency like $15,700

I have used conversion functions that converts $15,700 to 15700 like Ccur, Cstr, CDbl

When I use above functions on simple test they work properly but when I use them in my script I get Type mismatch error.

I have Created a variable Actual_Price for Actual Price because I am capturing an output from website and the using CAprice variable to convert Actual_Price output.

My script is given below I can share entire script if you want.

Thanks in advance.



Code:
Actual_Price = Browser("Micclass:=Browser","Creationtime:=0","Title:=.*").Page("Micclass:=Page","Creationtime:=0","Title:=.*").webelement("class:=calc-results-total","html id:=ac_max_tmv_result","html tag:=SPAN").GetROProperty("innertext")


Print Actual_Price & "  Before Conversion"

CAprice = Cdbl(Actual_Price)

Print "Actual Price " & Actual_Price  & " Converted Actual Price" & CAprice

Print " and Estimated Price is = " & Estimated_Price

If CAprice = Estimated_Price Then

Print " Actual Price Test Pass"

Else
Print "Actual Price Test Faill"



RE: Problem With conversion function - Ankur - 09-25-2018

Please show the exact place where you get the error.

Also, whatever you are comparing, try to convert to the same type.


RE: Problem With conversion function - wajid - 10-01-2018

CAprice = Cdbl(Actual_Price)   is the exact place - Here is where I try to convert actual price Variable that contain Price in $15,700 format.

I have a estimated price ( Estimated_Price)  in format like 15700
But on website I have out put (Actual_Price) in format like $15,700

How can I compare above prices to print Test Pass


Quote:If Actual_Price = Estimated_Price Then
Print " Actual Price Test Pass"
Else
Print "Actual Price Test Faill"

Above code does not work


Regards


RE: Problem With conversion function - wajid - 10-01-2018

Problem Solved 

Rewrote the script 

Used

Cdbl(Actual_Price) = Cdbl(Estimated_Price)