preload

DotNetFactory interface functions (3) – Create TextBox

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

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

Creating .NET objects from VBScript/QTP

You can create a TextBox (single-line Text Input object) and assign required properties within one line by calling the function below. The function has only optional parameters provided in the Dictionary object.

Currently supported optional parameters:

TextBox Width and Height.

TextBox Coordinates – Left, Top.

  • p.text – Text displayed by default
  • p.length – Max number of input characters
  • p.masked – If input needs to be secured (e.g. password textbox).
  • p.readonly – If editing is not allowed.

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

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

Used resources

Service Functions – String (QTP, VBScript)

Implementing optional and default parameters

 Create TextBox


 Public Function CreateTextBox(ByVal objParameter)
    Dim intLength
    Dim sText, intWidth, intHeight, intMaxLength, boolMasked, boolReadOnly
    Dim intLeft, intTop
    Dim objTextBox

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

  sText = objParameter.Item("p.text")
  intLength = Len(sText)
  If intLength = 0 Then
   intLength = 100
  Else
   intLength = (intLength + 6)*10
  End If
  
  intWidth = InitLong(objParameter.Item("p.width"), intLength)
  intHeight = InitLong(objParameter.Item("p.height"), 20)
  intLeft = IntVal(objParameter.Item("p.left"))
  intTop = IntVal(objParameter.Item("p.top"))
  intMaxLength = InitLong(objParameter.Item("p.length"), 255)
  boolMasked = InitBool(objParameter.Item("p.masked"), FALSE)
  boolReadOnly = InitBool(objParameter.Item("p.readonly"), FALSE)

  Set objTextBox = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")

  objTextBox.Text = sText
  objTextBox.Width = intWidth
  objTextBox.Height = intHeight
  objTextBox.Left = intLeft
  objTextBox.Top = intTop
  objTextBox.Multiline = FALSE
  objTextBox.MaxLength = intMaxLength

  If boolMasked Then
   objTextBox.UseSystemPasswordChar = TRUE
  End If
  objTextBox.ReadOnly = boolReadOnly

  Set CreateTextBox = objTextBox
 End Function

Examples


Set objInputUserID = CreateTextBox(AssociateParameters("p.left = 25, p.top = 100"))
Set objInputPassword = CreateTextBox(AssociateParameters("p.left = 25, p.top = 150, p.masked = Yes"))


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.