This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

WaitForText1 with RegularExpression option clarification

I'm hoping someone can give some information on the "textComparisonOption_RegularExpression" option to the WaitForText1 method (Reflection 14). The usage doesn't seem documented whatsoever.

I have a case where text may appear in column 1 or 2 (don't know until it does) and need some way of using that method to know when the specific text appears--but since it can be in either column there's no way to use it to determine if it's there reliably.  I'm hoping there's a regexp method that will help by letting me specify column 1, and determining if the text is there. (ie, " my_text" (leading space) and "my_text" (no leading space) would both result in "true".




  • Hi Daniel, 

    unfortunately there is no out of the box method to achieve this.

    Here is a Function that you can use to search a portion of the screen, either a rectangular portion or a portion that wraps around at the end of line.

    Private Function myWaitForStringInArea(myString As String, ByRef startRow As Integer, ByRef startCol As Integer, ByRef endRow As Integer, ByRef endCol As Integer, ByRef BlockOrStream As Boolean, ByRef Timeout As Long) As Boolean

        Dim TextInSearchRegion As String, StringFound As Integer, SetTimeout As Long
        StartTime = Timer

        StringFound = 0
        SetTimeout = Timeout

        Do While Timer - StartTime < (SetTimeout / 1000)
            TextInSearchRegion = ThisIbmScreen.GetTextEx(startRow, startCol, endRow, endCol, BlockOrStream, GetTextWrap_Off, GetTextAttr_Any, GetTextFlags_None)
            StringFound = InStr(1, UCase(TextInSearchRegion), UCase(myString))
            If StringFound > 0 Then
                If BlockOrStream = 0 Then
                    absolutePosition = startRow * ThisIbmScreen.columns + startCol + StringFound
                    startRow = CInt(absolutePosition / ThisIbmScreen.columns)
                    startCol = (absolutePosition Mod 80) - 1
                    relativePosition = startRow * (endCol - startCol + 1)
                    startRow = startRow + CInt((StringFound) / (endCol - startCol + 1))
                    startCol = startCol + CInt((StringFound) Mod (endCol - startCol + 1)) - 1
                End If
                Timeout = (Timer - StartTime) * 1000
                myWaitForStringInArea = True
                Exit Do
                myWaitForStringInArea = False
            End If
        If myWaitForStringInArea = False Then
            startRow = 0
            startCol = 0
            Timeout = 0
        End If
    End Function

    To use this function you provide the text you are looking for, the area in which you want to wait for the text, whether it's a block (rectangular) or not (then it's stream) and a timeout in milliseconds.

    The function returns True if the text is found in the search area. If the text is found, the position of the string you are waiting for is returned in the startRow and startCol parameter variables and the duration of the wait is returned in the timeout parameter.

    If the text is not found, then the function returns False, and the startRow, endRow and Timeout parameter are all returned as 0.

    Here is a sample call from inside a routine. If sets the search area to row 5 from column 2 to 3 and checks that for for a "d" anywhere in that area 

    Dim myString As String

    Dim startRow As Integer
    Dim startCol As Integer
    Dim endRow As Integer
    Dim endCol As Integer
    Dim Block As Boolean 'True == Rectangular area, False == Stream with wrapping at end of line
    Dim Timeout As Long
    Dim Found As Boolean

    ' ThisIbmScreen.SendControlKey ControlKeyCode_Transmit

    startRow = 10
    startCol = 2
    endRow = 10
    endCol = 3
    myString = "d"
    Block = True
    Timeout = 10000

    Found = myWaitForStringInArea(myString, startRow, startCol, endRow, endCol, Block, Timeout)

    If Found = True Then
        MsgBox "Found Text string " & Chr$(34) & myString & Chr$(34) & " at Row: " & startRow& " Col: " & startCol & " in " & Timeout & "msec"
        MsgBox "Text did not appear before the wait timed out"
    End If


    If you need something similar in the legacy Reflection COM api, then you can follow the same logic to create your own custom WaitForMyCondition, 

  • Tom, I can't think you enough for that--it's exactly what I needed, and worked perfectly! 

    I probably should have come up with that method myself, but was focused on getting the WaitForText1 to work!  

    Thanks sooo much again!  I really really appreciate you taking the time!