Scenario: An enabled application contains a window title with a name in it, which needs to be parsed out. The window title is mapped to a "First Name" keyword, and a "Last Name" keyword. The following example uses a pre-processing script to parse the First Name and Last Name values out of the window title.
Window title example: "Customer Name - John Doe. #15398"
-
Function FirstName(InputValue)
Declare a string to temporarily hold data.
-
Dim strTempValue
Parse out the first name value from the window title.
Assuming “Customer Name – “ will always be part of the window title, parsing will start at the 17th character.
To determine when the first name ends, which will be the first occurrence of a space after the 17th character, declare a variable to store the location of the first space, after the 17th character.
-
Dim intSpaceLocation
Using the InStr( ) function, determine the location of the first space after the 17th character
-
intSpaceLocation = InStr(17, InputValue, " ")
Parse the first name using the previous values
-
strTempValue = mid(InputValue, 17, intSpaceLocation - 17)
Return the parsed value by setting the function equal to the value.
-
FirstName = strTempValue
End Function
Function LastName(InputValue)
Declare a string to temporarily hold data.
-
Dim strTempValue
Parse out the last name value from the window title.
Assuming “Customer Name – “ and a first name will always be part of the window title, we will start after the first name.
Determine when the first name ends, which will be the first occurrence of a space after the 17th character.
Declare variables to store the location of the first space after the 17th character, and first period after the space.
-
Dim intSpaceLocation
Dim intPeriodLocation
Using the InStr( ) function, determine the location of the first space after the 17th character.
-
intSpaceLocation = InStr(17, InputValue, " ")
Using the InStr( ) function, determine the location of the first period after the first space.
-
intPeriodLocation = InStr(intSpaceLocation, InputValue, ".")
Parse the last name using the previous values
-
strTempValue = mid(InputValue, intSpaceLocation, intPeriodLocation - intSpaceLocation)
Return the parsed value by setting the function equal to the value.
-
LastName = strTempValue
End Function
The script in its entirety:
Function FirstName(InputValue)
Dim strTempValue
Dim intSpaceLocation
intSpaceLocation = InStr(17, InputValue, " ")
strTempValue = mid(InputValue, 17, intSpaceLocation - 17)
FirstName = strTempValue
End Function
Function LastName(InputValue)
Dim strTempValue
Dim intSpaceLocation
Dim intPeriodLocation
intSpaceLocation = InStr(17, InputValue, " ")
intPeriodLocation = InStr(intSpaceLocation, InputValue, ".")
strTempValue = mid(InputValue, intSpaceLocation, intPeriodLocation - intSpaceLocation)
LastName = strTempValue
End Function