preload

DotNetFactory interface functions – create custom dialog

Posted by Albert Gareev on Jun 18, 2009 | Categories: Source code

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

Used resources

Service Functions – String (QTP, VBScript)

Implementing optional and default parameters

 Create TextBox along with the Prompt Label and place on the GUI Form.


 Public Function PlaceTextBox(ByRef objForm, ByVal objParameter)
    Dim sPrompt
    Dim intLeft, intTop
    Dim objTextBox, objLabel

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

  sPrompt = objParameter.Item("p.prompt")
  If sPrompt = "" Then sPrompt = "Input value"

  Set objTextBox = CreateTextBox(objParameter)

  intLeft = objTextBox.Left
  intTop = objTextBox.Top
  Set objLabel = CreateLabel(sPrompt, AssociateParameters("p.left = " & intLeft & " , p.top = " & intTop - 20))
  
  objForm.Controls.Add(objLabel)
  objForm.Controls.Add(objTextBox)

  Set PlaceTextBox = objTextBox
 End Function

Create ComboBox along with the Prompt Label and place on the GUI Form.


 Public Function PlaceComboBox(ByRef objForm, ByVal objItems, ByVal objParameter)
    Dim sPrompt
    Dim intLeft, intTop
    Dim objComboBox, objLabel

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

  sPrompt = objParameter.Item("p.prompt")
  If sPrompt = "" Then sPrompt = "Select value"

  Set objComboBox = CreateComboBox(objItems, objParameter)

  intLeft = objComboBox.Left
  intTop = objComboBox.Top
  Set objLabel = CreateLabel(sPrompt, AssociateParameters("p.left = " & intLeft & " , p.top = " & intTop - 20))
  
  objForm.Controls.Add(objLabel)
  objForm.Controls.Add(objComboBox)

  Set PlaceComboBox = objComboBox
 End Function

 Create Button, assign the event, and place on the GUI Form.


 Public Function PlaceButton(ByRef objForm, ByVal sText, ByVal objParameter)
    Dim objButton

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

  Set objButton = CreateButton(sText, objParameter)

  Select Case UCase(objParameter.Item("p.result"))
   Case "ABORT", "CANCEL", "NO"
    Set objForm.CancelButton = objButton
   Case "OK", "RETRY", "YES"
    Set objForm.AcceptButton = objButton
  End Select

  objForm.Controls.Add(objButton)

  Set PlaceButton = objButton
 End Function

Example.


Set objForm = CreateForm("Test Setup", AssociateParameters("p.startpos = CenterScreen, p.width = 400, p.height = 300, p.locksize = Yes, p.lockview = Yes"))

Set objSelectEnvironment = PlaceComboBox(objForm, AssociateParameters("1 = DEV1, 2 = DEV2, 3 = UAT"), AssociateParameters("p.prompt = Test Environment, p.left = 25, p.top = 50, p.item = DEV2"))
Set objInputUserID = PlaceTextBox(objForm, AssociateParameters("p.prompt = User ID, p.left = 25, p.top = 100"))
Set objInputPassword = PlaceTextBox(objForm, AssociateParameters("p.prompt = Password, p.left = 25, p.top = 150, p.masked = Yes"))

Set objOK = PlaceButton(objForm, "OK", AssociateParameters("p.left = 124, p.top = 200, p.width = 75, p.result = OK"))
Set objCancel = PlaceButton(objForm, "Cancel", AssociateParameters("p.left = 200, p.top = 200, p.width = 75, p.result = Cancel"))

objForm.Activate()
objForm.ShowDialog()
  • One response to "DotNetFactory interface functions – create custom dialog"

  • Roj
    11th April 2010 at 18:29

    Albert,

    Can you also provide an example of how to get those values once dialog is closed?

    Thanks.

    [ Albert's Reply.
    Roj,
    You simply need to access the properties of objects you put on GUI form.
    E.g. objInputUserID.Text to retrieve text value. ]

  • Leave a Reply

    * Required
    ** Your Email is never shared