Action
Substitutes new text for all or part of the text in the text field.
Syntax
textfield.SetText (sText [, iStartChar, iNumChars])
Variable
|
Description
|
sText
|
The text to substitute.
STRING.
|
iStartChar
|
Optional: The character position in the text field (starting from 1) at which to begin the substitution.
INTEGER.
|
iNumChars
|
Optional: The number of characters in the text field to substitute with
sText.
INTEGER.
|
Notes
- SetText substitutes the characters
sText for the text in the text field. This method works only with the first line of multi-line text fields.
- If
iStartChar is specified,
SetText substitutes
sText for the characters starting with the
iStartChar character, and continuing to the end of the line. If both
iStartChar and
iNumChars are specified, it substitutes
sText for
iNumChars characters starting with the
iStartChar character.
- If
iStartChar is omitted,
SetText substitutes
sText for the entire contents of the text field.
- SetText sets up to 1024 characters.
- If the
SetText method does not work as expected, you can try the
TypeKeys method.
Example 1
STRING sHello = "Hello, world"
Find.FindWhat.SetText (sHello)
Example 2
The following example illustrates date transformation using the
Text Field window in the test application shipped with
Silk Test Classic.
testcase GetandSetText1 ()
STRING sReturnedText
TextFieldWindow.Invoke ()
Print ("Entering the value '9/18/02'")
TextFieldWindow.TheTextField.SetText ("9/18/02")
Print ("Getting...")
sReturnedText = TextFieldWindow.TheTextField.GetText ()
Print (sReturnedText)
TextFieldWindow.Close ()
// Result:
// Entering the value '9/18/02'
// *** Y2K Notification: date value '9/18/02' has been
changed to '09/18/2003' in TextFieldWindow.TheTextField.SetText
// Getting ...
// 09/18/2003
Note the following about this test:
- The argument to
SetText is "9/18/02". That date is of the input form m/dd/yy so it matches the rule. Therefore, the date is transformed to the form mm/dd/yyyy. In this case, the date is set to 09/18/2003, as shown in the return from
GetText.
-
Silk Test Classic includes a notification message that the date has been transformed.
Example 3
This example illustrates date transformation using the
Text Field window in the test application shipped with
Silk Test Classic.
testcase GetandSetText2 ()
STRING sReturnedText
TextFieldWindow.Invoke ()
Print ("Entering the value '9/18/20'")
TextFieldWindow.TheTextField.SetText ("9/18/20")
Print ("Getting...")
sReturnedText = TextFieldWindow.TheTextField.GetText ()
Print (sReturnedText)
TextFieldWindow.Close ()
// Result:
// Entering the value '9/18/20'
// *** Y2K Notification: date value '9/18/20' has been
changed to '09/18/2020' in TextFieldWindow.TheTextField.SetText
// Getting ...
// 09/18/2020
Note the following about this test:
- The argument to
SetText is "9/18/20", also of the input form m/dd/yy, so it matches the rule.
- In this case, the year (20) is below the threshold in the rule (30), so the date is converted to 2020, instead of 1920.