DotNetFactory interface functions (4) – Create CheckBox

Posted by Albert Gareev on Jun 15, 2009 | Categories: DotNetClassesSource code

Parent page: Service Functions – DotNetFactory (QTP, VBScript)

Creating .NET objects from VBScript/QTP

You can create a CheckBox and assign required properties within one line by calling the function below. The function has one mandatory parameter (which though is initialized by default if empty) and a set of optional parameters provided in the Dictionary object.

Currently supported optional parameters:

CheckBox Width and Height.

CheckBoxCoordinates – Left, Top.

p.checked – Initial state.

Note. You may code as many optional parameters as required. Just follow the established syntax and keep in mind that parameter index for Dictionary must be unique – otherwise it will overwrite the previous parameter.


For the complete .NET CheckBox Class reference please visit:

Used resources

Service Functions – String (QTP, VBScript)

Implementing optional and default parameters

Create CheckBox

 Public Function CreateCheckBox(ByVal sText, ByVal objParameter)
    Dim intLength
    Dim intWidth, intHeight, boolChecked
    Dim intLeft, intTop
    Dim objCheckBox

  'Verify parameters
  If TypeName (objParameter) <>  "Dictionary" Then
   Set objParameter = CreateObject("Scripting.Dictionary")
  End If

  If sText = "" Then sText = "Default"
  intLength = (Len(sText) + 4)*10
  intWidth = InitLong(objParameter.Item("p.width"), intLength)
  intHeight = InitLong(objParameter.Item("p.height"), 20)

  intLeft = IntVal(objParameter.Item("p.left"))
  intTop = IntVal(objParameter.Item(""))

  boolChecked = InitBool(objParameter.Item("p.checked"), FALSE)

  Set objCheckBox = DotNetFactory.CreateInstance("System.Windows.Forms.CheckBox", "System.Windows.Forms")
  objCheckBox.Text = sText
  objCheckBox.Width = intWidth
  objCheckBox.Height = intHeight
  objCheckBox.Left = intLeft
  objCheckBox.Top = intTop
  objCheckBox.Checked = boolChecked

  Set CreateCheckBox = objCheckBox
 End Function


Set objOverridePsw = CreateCheckBox("Override", AssociateParameters("p.left = 10, = 35, p.checked = Yes"))

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.