Example of class in Vbscripting

Here is a example for defining a Class, setting the values using Property and working with methods using Object of class.

Understanding Class in Vbscripting‘********************************Code for Class********************************
‘Defining a Class
Class UFTHelp
      ‘Declaring variables inside class
      Private sTool,sVersion
      ‘Using Let property for Setting the values of class members
      Public property Let Tool (sUFT)
            Select case sUFT
                  Case “UFT”
                        sTool = sUFT
                  Case “QTP”
                        sTool = sUFT
                  Case Else
                        Msgbox “Please enter Correct Tool to learn”
            End Select
      End Property
      ‘Method declaration
      Public Sub version(sHP)
            Select case sHP
                  Case “11.5”
                        If sTool = “UFT” Then
                              Msgbox “I want to learn ” &sTool&” “&sHP
                        End If
                  Case “11”
                        If sTool = “QTP” Then
                              Msgbox “I want to learn ” &sTool&” “&sHP
                        End If
                  Case Else
                        Msgbox “Please enter correct Version of Tool”
            End Select
      End Sub
End Class
‘Creating objects of class
Dim objHelp
Set objHelp = New UFTHelp
‘Setting the value of Local variable(Change value of TOOL and version to observe the behaviour)
objHelp.Tool= “UFT”
‘Calling the methods of class 
‘Destroying the object
Set objHelp = nothing

Leave a Reply

Your email address will not be published. Required fields are marked *