Automation Testing

7 QTP Casting Functions to Make You a QTP Automation Wizard

By Test Guild
  • Share:
Join the Guild for FREE

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.

  • CInt()

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:

‘Good script example:

  • CBool

To return a Boolean value of an expression for true/false conditions — Hocus-pocus, Allakhazam!:

  • CLong

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:

msgbox CLng("6,579.56")

will return a value of 6580

  • Asc

msgbox Asc("J") returns a value of 74, which is the ANSI code for “J”

  • Cbyte

msgbox Cbyte("7.77") returns a value of 8 because the value is rounded up

  • ChrB

msgbox ChrB(74) returns a value of J, which is the number 74 in the ANSI table

  • HEX

And finally, to use QTP to put a “Hex” on a bug (…get it?) use the HEX function:

msgbox Hex(16777215) — 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

  1. Hi, Joe!

    Nice examples!
    This is not a functionality of QTP. These functions are the part of native VBScript; we can use them in shell scripts, in TestComplete, or in other tools which employ MS scripting engine.

    Thanks,
    Albert

  2. Hi Albert – that is good point! It is true that QTP uses the VBScript script engine for these functions. Thanks for your comment!!

  3. Hi Joe. If you change YourQTPCastingSkill to “17” in your examples you’ll actually drive the point home.
    “17” CINT(“3”)

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Top 8 Automation Testing Trends Shaping 2025

Posted on 01/11/2025

As we enter 2025, here are some automation testing trends I think will ...

DevAssure Review: Cut Testing Time Using Low Code Automation?

Posted on 12/11/2024

As you know, testing often becomes a bottleneck in software development due to ...

Leveraging AI and Playwright for Test Case Generation

Posted on 11/22/2024

Two BIG trends the past few years in the software testing space been ...

AG '25 Online Event: Defeat Flaky Tests, Future-Proof Your Skills, & Grow Your Network in 2025 - Learn More >>

⭐⭐⭐⭐⭐ “A must-attend virtual event for all testing professionals.” — George Ukkuru (Head of Quality Eng.)