Tuesday, April 27, 2010

Classes in VB script for QTP

Creating classes in VBScript is really no different than creating classes in any other programming language. The concept of an object is usually described as just about anything. When you think about it every thing around you is some sort of object. For example a house is an object. It has properties and methods. The properties could be that the house has 3 bedrooms, a garage, a pool, air conditioning etc. You can even break down the house into smaller objects, such as doors windows etc. A garage door may have methods that are controlled by a remote. The methods may be something like garageDoor.open or garageDoor.close. The garage door would be an object, and the method would be to open or close. Getting back to the Vb Script, lets see how we would write a simple class called Math that adds or subtracts two numbers. First let’s look at our parameters for the class.
Class Name: Math
Methods: add and subtract
Now before we actually create the class, lets just see how we would write the two methods:
Public Function add(afirst, asecond)
Dim output
output = afirst + asecond
add = output
End Function
Public Function subtract(sfirst, ssecond)
Dim output
output = sfirst - ssecond
subtract = output
End Function
Now we can define the class:
Class Math
End Class
Then just put them together:
Class Math
Public Function add(afirst, asecond)
Dim output
output = afirst + asecond
add = output
End Function
Public Function subtract(sfirst, ssecond)
Dim output
output = sfirst - ssecond
subtract = output
End Function
End Class

1 comment:

  1. Hey, I think your site might be having browser compatibility issues.
    When I look at your blog site in Opera, it looks fine but when opening in Internet Explorer, it has some overlapping.

    I just wanted to give you a quick heads up! Other then that, very
    good blog!



    http://www.visioneducativa.cl/wiki/index.php?title=Usuario:BernieBaptiste

    Stop by my web blog :: hvac minneapolis mn

    ReplyDelete

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons