DotNetFactory interface functions (2) – Create Label

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

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

Creating .NET objects from VBScript/QTP

You can create a label 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:

Label Width and Height.

Label Coordinates – Left, Top.

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 Label Class reference please visit:

Used resources

Service Functions – String (QTP, VBScript)

Implementing optional and default parameters

Create Label

 Public Function CreateLabel(ByVal sText, ByVal objParameter)
    Dim intLength
    Dim intWidth, intHeight
    Dim intLeft, intTop
    Dim objLabel

  '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(""))

  Set objLabel = DotNetFactory.CreateInstance("System.Windows.Forms.Label", "System.Windows.Forms")
  objLabel.Text = sText
  objLabel.Width = intWidth
  objLabel.Height = intHeight
  objLabel.Left = intLeft
  objLabel.Top = intTop

  Set CreateLabel = objLabel
 End Function


Set objPromptLabel = CreateLabel("Please provide your Username and Password", AssociateParameters("p.left = 10, = 15, p.width = 200, p.height = 25"))

  • Leave a Reply

    * Required
    ** Your Email is never shared

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.