Results 1 to 8 of 8
  1. #1

    Are there Regular Expressions in TP?

    Hi all
    Does anybody know how to use regular expressions?
    I m stuck at it and not able to find anything on it.
    i havent seen even a single feature which shows that such a thing exists even.
    i know its a very basic thing and must be there, but sadly i have failed to find it.

    Any help will be greatly appreciated.
    Thanks And Regards

  2. #2
    Senior Member
    Join Date
    Nov 2002
    Lausanne, Switzerland

    Re: Are there Regular Expressions in TP?

    You need to include the reference to Microsoft VBScript Regular Expressions 5.5.
    And here is an exemple:

    Sub Main()
    Dim regExpr As New RegExp
    Dim mc As MatchCollection
    Dim mtch As Match
    Dim stringToFind As String
    Dim stringToSearch As String
    Dim nbWords As Integer

    stringToFind = "test"
    stringToSearch = "Test and test!"

    'nbWords = hc.Words(b, "*")
    'MsgBox (nbWords)

    regExpr.IgnoreCase = True
    regExpr.Global = True
    regExpr.Pattern = stringToFind

    Set mc = regExpr.Execute(stringToSearch)

    For Each mtch In mc
    MsgBox (mtch.Value)
    Next mtch

    End Sub

  3. #3

    Re: Are there Regular Expressions in TP?

    jmi, thanks so much for your reply

    But there is still a bit more which i need.
    how do we use the wild characters for matching say test_1 and test_2 and test_3

    actually i have a child window , to which i need to attach, but it's name is dynamic...so i do believe that i need wild characters as well....

    Also if you could please explain how to include reference to Microsoft VBScript Regular Expressions 5.5

    Or if you could tell a place where i can read about it.

    Waiting for your reply
    thanks once again
    Thanks And Regards

  4. #4

    Re: Are there Regular Expressions in TP?

    Look for "Like" operator in Visual Basic help. If you need to do simple wildcard matches it's enough with Like, you don't need regular expressions reference.

  5. #5
    Senior Member
    Join Date
    Nov 2002
    Lausanne, Switzerland

    Re: Are there Regular Expressions in TP?

    To include the reference: menu Tools->References and then check "Microsoft VBScript Regular Expressions 5.5".

    For matching with wild cards :
    stringToFind = ".*test.*"
    stringToSearch = "Test and test!"
    If reg regExpr.Test(StringToSearch) = True Then
    MsgBox("no match"

    In this exemple ".*" means any "any number of any characters except LF (\n). In the variable stringToSearch you can put any regular expressions you want and then use the functions Execute or Test.

  6. #6

    Re: Are there Regular Expressions in TP?

    this is kiran
    the way i worked with Regular expressions is different
    get caption of the window
    if window.caption("'Name*'").exists then
    do action
    as per ur problem
    window.caption("Name='test*'").exists then
    pls try this and let me know the output.
    thanks and regards,
    Best Wishes,

  7. #7
    Advanced Member
    Join Date
    Jan 2002
    Detroit, Michigan

    Re: Are there Regular Expressions in TP?

    Try the following

    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">On Error Resume Next

    If Window(&quot;Caption='Hello From *'&quot;, tpAttachNoWait).Exists Then
    MsgBox &quot;Existing&quot;
    MsgBox &quot;Not Existing&quot;
    End If

    On Error GoTo 0</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">The line On Error Resume Next stops TestParnter throwing an error if the window could not be found.

    The Exists property returns True or False depending on whether the window exists or not.

    The specification of the caption in the window shows the * being used as a wildcard.

    The tpAttachNoWait is used to check immediatly without using the Playback.AttachTimeout value in the settings.

    The line On Error Goto 0 resets the error handling back to the default.

  8. #8

    Re: Are there Regular Expressions in TP?

    If you use tpAttachNoWait parameter you don't need to have "On Error Resume Next". The test won't stop even if the Window is not found and no error is recorded to the log.

    Here's extract from TestPartner help file:

    Performs the attach without waiting. This suppresses the exception handling and the object receiving the result of the construction function can be validated using the Exists property.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 05:40 PM.

Copyright BetaSoft Inc.