If you’re striving to become the next Harry Potter or Gandalf the Gray of QTP, then learn this lesson well. Your quest, if you choose to accept it, is to seek out the scroll of casting. Do so and unlock the key to QTP’s casting conversion functions.
To transform strings into integers, you first need to use Cint() to cast the string to its integer value. If you don’t, the enchanted VBScript engine interprets the values as strings, not numbers! For example:
‘Bad script example:
YourQTPCastingSkill = "7" BugsSkill = "3" If (YourQTPCastingSkill > BugsSkill) Then msgbox "You win -- your QTP CINIT casting spell detects and crushes the software bug!" Else msgbox "You lose -- the bug eludes you and makes it into the production!" End If
‘Good script example:
YourQTPCastingSkill = "7" BugsSkill = "3" If (CINT(YourQTPCastingSkill) > CINT(BugsSkill)) Then msgbox "You win -- your QTP CINIT casting spell detects and crushes the software bug!" else msgbox "You lose -- the bug eludes you and makes it into the production build." End If
To return a Boolean value of an expression for true/false conditions — Hocus-pocus, Allakhazam!:
wizardNum = 7 If CBOOL(wizardNum) = "True" then msgbox "I have summoned the power of Cbool!" End If
If a value needs to be between -2147483648 and 2147483647, and a value of, say, 6,579.56 is used, you can change it by using CLNG:
will return a value of 6580
returns a value of 74, which is the ANSI code for “J”
returns a value of 8 because the value is rounded up
returns a value of J, which is the number 74 in the ANSI table
And finally, to use QTP to put a “Hex” on a bug (…get it?) use the HEX function:
— this will return the Hex value of FFFFFF which, by the way, is the hexadecimal number for the color black.
If you got a chuckle out of this blog, and enjoy reading, you might like the book Wizard’s Bane by Rick Cook — a comical fantasy about a programmer who invents a computer language for casting magic spells. A free online version of the book can be found here