Automation Beyond

Testing and Test Automation for Software Quality Assurance. Above Requirements. Beyond Expectations. Methodologies and concepts. Framework Design. Programming and Scripting. Created by Albert Gareev.

DotNetFactory interface functions (1) – Create Button

Posted by Albert Gareev on 2009/06/12

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

One Response to “DotNetFactory interface functions (1) – Create Button”

  1. [...] DotNetFactory interface functions (1) – Create Button [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>