preload

DotNetFactory interface functions (1) – Create Button

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

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

Creating .NET objects from VBScript/QTP

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

Button Width and Height.

Button 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.

References

For the complete .NET Button Class reference please visit:

http://msdn.microsoft.com/en-us/library/system.windows.forms.button(VS.80).aspx

Used resources

Service Functions – String (QTP, VBScript)

Implementing optional and default parameters

Create Button


 Public Function CreateButton(ByVal sText, ByVal objParameter)
    Dim intLength
    Dim intWidth, intHeight
    Dim intLeft, intTop
    Dim objButton

  '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"), 24)

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

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

  Set CreateButton = objButton
 End Function

Example

Set btnOK = CreateButton("OK", AssociateParameters("p.left = 90, p.top = 150"))

  • 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.