preload

DotNetFactory interface functions – create custom dialog

Posted by Albert Gareev on Jun 18, 2009 | Categories: DotNetClassesHow toSource 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

Examples


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


  • 2 responses 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. ]

  • Ashok
    17th May 2011 at 16:29

    Albert,

    Can you please explaing how to capture events? For example i have form with two buttons. i want to do two differnet operations on click of buttons.

    [ Albert’s reply. I’m busy with something else these days. If your question is urgent, I recommend StackOverflow. ]

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.