DotNetFactory interface functions (4) – Create CheckBox
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.
References
For the complete .NET CheckBox Class reference please visit:
http://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox(VS.80).aspx
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("p.top"))
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
Example
Set objOverridePsw = CreateCheckBox("Override", AssociateParameters("p.left = 10, p.top = 35, p.checked = Yes"))

