Micro Focus QTP (UFT) Forums
cbool & eval - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: cbool & eval (/Thread-cbool-eval)



cbool & eval - Sivapratha - 02-15-2013

Hi,
Can anyone explain the difference between cbool and eval func with example?

Thanks in advance...


RE: cbool & eval - newqtp - 02-15-2013

In vbscript x = y can be interpreted two ways. The first is as an assignment statement, where the value of y is assigned to x. The second interpretation is as an expression that tests if x and y have the same value. We use Eval method if x=y result is True; if they are not, the result is False.

And CBool method test, if expression x=y evaluates to a nonzero value, returns True; otherwise, it returns False.

Code:
Dim A, B, Check , c, D
A = 10: B = 5:  c=5 : D=10      ' Initialize variables.

If Eval("A = B") Then
         MsgBox "Congratulations! A is equal to B"
      Elseif Eval("C=B") then
    Msgbox "Congratulation! B and C are equal"
End If

'Cbool example

Check = CBool(A = B)   ' Check contains False.
msgbox Check
A = 10                  ' Define variable.
Check = CBool(A)       ' Check contains False.
msgbox check
check = CBool(C=B) ' Check contains True.
msgbox check