Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for more instances of a string 2

Status
Not open for further replies.

dvirgint

Programmer
Jun 28, 2010
85
0
0
CA
Hello all,

I have information in Extra! that I need to extract. I created an Excel file to be able to manipulate the data which I will extract.

My problem is getting my macro to see more than one instance of the string I'm searching for, as it is probable there will be more than one on each page. With [blue]Sess0.Screen.Search[/blue], I cannot get it to find more than one.

I assume that I have to write the code so that the macro will search line by line to find the string? If so, can I add something at the beginning of my code to do a general search on the page for the string - if nothing is found, it changes pages - if the string is found, then it goes line by line?

I have included my code. Any suggestions?

Code:
Dim System As Object, Sess0 As Object, MyScreen As Object
Set System = CreateObject("EXTRA.System")
Set Sess0 = System.ActiveSession
Set MyScreen = Sess0.Screen
Dim i As Integer

Set tot_pages = MyScreen.area(1, 66, 1, 68)
ex_line = 2

Do       
        Set rad_find = Sess0.Screen.Search("String needed")
        If rad_find <> "String needed" Then
            Sess0.Screen.SendKeys ("<pf8>")
        Else
            rad_tax_year = Sess0.Screen.GetString(rad_find.Bottom, rad_find.Right - 17, 4)
            Sheets("Chiffres").Cells(ex_line, "a") = rad_tax_year
            If i = 12 Then
                Exit Do
            End If
        End If

        i = i + 1
    Loop Until i = tot_pages

Thanks for your help.
dvirgint
 
OK, I'm making progress. The macro now finds all instances on the page, however it still goes from line 5 (which I set earler) to line 24. Your earlier post of 10:19 states:

You FIND the first.

Then for the next search, supply a ROW that is AFTER that occurrence.

How can I get the macro to start the search on a particular line?

Here is the modified code I'm using.

Code:
Do
        
        line_number = 5
        Set rad_find = Sess0.Screen.Search("Radiation par")
        If rad_find <> "Radiation par" Then
            Sess0.Screen.SendKeys ("<pf8>")
            Sess0.Screen.WaitHostQuiet (100)
        Else
            Do       
                Set rad_find = Sess0.Screen.Search("Radiation par", line_number) 'I added line_number
                If rad_find = "Radiation par" Then
                    rad_tax_year = Sess0.Screen.GetString(rad_find.Bottom, rad_find.Right - 17, 4)
                    Sheets("Chiffres").Cells(ex_line, "a") = rad_tax_year
                End If
                line_number = line_number + 1
                'MsgBox line_number
            Loop Until line_number = 23
            ex_line = ex_line + 1
            Sess0.Screen.SendKeys ("<pf8>")
            Sess0.Screen.WaitHostQuiet (100)
        End If
        i = i + 1
    Loop Until i = tot_pages

Thanks for your patience, Skip!!
 


16 Jan 12 9:38

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


That is referring to HELP on the Search Method.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
see if this helps you understand
Code:
Sub Main
    Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object
    Set Sys = CreateObject("EXTRA.System")
    Set Sess = Sys.ActiveSession
    Set MyScreen = Sess.Screen

    r = 1
    c = 1 
    
    Do
    
        Set MyArea = MyScreen.Search("HELLO",r,c)
        MyScreen.MoveTo MyArea.Bottom, MyArea.left
        row = MyScreen.row
        col = MyScreen.col
        
        if row = 1 and col = 1 then
            msgbox "no more"
            exit sub
        else
            MyScreen.MoveTo MyArea.Bottom, MyArea.right + 1
            r = MyScreen.row
            c = myScreen.col
            
        end if
                
        
    Loop
    
End Sub
 
Does my code from earlier:
Code:
Set n_5 = MyScreen.area(line_number, 2, line_number, 80)

... set the coordinates for Sess0.Screen.Search?

 
dvirgint,

if a search is successful, the row/col coordinates are changed, otherwise it goes to 1,1

include the row, col within the search string
 
Yes vzachin, that's very helpful, thank you. I see what you did, and understand - I'm very visual, so a small example helps a lot!!
 

SkipVought/ExtraVB_Help said:
Description

Returns an Area object with the text specified in the search.

Syntax

Set rc = object.Search(Text[,Row][,Col][,Page])

Element Description
Set The Set statement, required for assigning an object reference to a variable.
rc The object variable for referencing the returned object.
object The Screen object.
Row The row where the search begins.
Col The column where the search begins.

Comments

If the optional parameters are used, Screen is searched from the specified starting position. Otherwise, the entire Screen object is searched.
If Search finds the specified text, the coordinate properties (Left, Top, Right, Bottom) of the returned Area object are set to the starting and ending row and column positions of the text.
The Value property of the Area object is set to the text located at those coordinates. If the Screen changes at those coordinates, the Value property of the Area changes.

If Search does not find the specified text, the Area object's Value property is set to an empty string, its Type property is set to xNONE, and its coordinate properties are set to -1.


Copyright 1996 - 1999, Attachmate Corporation. All rights reserved.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
vzachin,

The code you gave for some reason doesn't seem to work. It goes to the first place on the page where the string is found, however after it doesn't go to the next. If there is only one instance on the page, the coordinates stay the same after it has been found, instead of returning to 1, 1.

And I copied your code into a new module to make sure I wasn't missing something.

Am I missing something?
 
dvirgint,

without seeing your code, i'm not sure what it's doing. after finding the first string, where did you place the cursor? i'm thinking if your found string is at the end of the row, this may fail.

when you copied my code into a module, did you try it out with the search for "HELLO" and see if that works?

zach
 
Hi Zach,

Yes, in the new module, I used "HELLO" and that did not work. The cursor did not move. It stayed at the same coordinates (1,60). Any idea why?

And here is the updated code. I tried changing a few things to make it fit with what I needed it for...

Code:
    r = 1
    c = 1
    ex_line = 2
    
    Do
        
        Set rad_find = Sess0.Screen.Search("Radiation par")
        If rad_find <> "Radiation par" Then
            Sess0.Screen.SendKeys ("<pf8>")
            Sess0.Screen.WaitHostQuiet (100)
        Else
            
            Do
                
                Set rad_find = MyScreen.Search("Radiation par")
                MyScreen.MoveTo rad_find.Bottom, rad_find.Left
                Row = MyScreen.Row
                col = MyScreen.col
                MsgBox col
                If rad_find = "Radiation par" Then
                    rad_tax_year = Sess0.Screen.GetString(rad_find.Bottom, rad_find.Right - 17, 4)
                    Sheets("Chiffres").Cells(ex_line, "a") = rad_tax_year
                    ex_line = ex_line + 1
                    MyScreen.MoveTo rad_find.Bottom, rad_find.Right + 1
                    r = MyScreen.Row
                    c = MyScreen.col
                    MsgBox Row
                    MsgBox col
                    Row = Row + 1
                End If
                'r = Row + 1
                
            Loop Until Row = 23
            Sess0.Screen.SendKeys ("<pf8>")
            r = 1
            c = 1
            Sess0.Screen.WaitHostQuiet (100)
        End If
        i = i + 1
    Loop Until i = tot_pages

Thanks again for your help.
 

AGAIN!!! said:
Description

Returns an Area object with the text specified in the search.

Syntax

Set rc = object.Search(Text[,Row][,Col][,Page])

Element Description
Set The Set statement, required for assigning an object reference to a variable.
rc The object variable for referencing the returned object.
object The Screen object.
Row The row where the search begins.
Col The column where the search begins.

Comments

If the optional parameters are used, Screen is searched from the specified starting position. [highlight]Otherwise, the entire Screen object is searched[/highlight].

If Search finds the specified text, the coordinate properties (Left, Top, Right, Bottom) of the returned Area object are set to the starting and ending row and column positions of the text. The Value property of the Area object is set to the text located at those coordinates. If the Screen changes at those coordinates, the Value property of the Area changes.

If Search does not find the specified text, the Area object's Value property is set to an empty string, its Type property is set to xNONE, and its coordinate properties are set to -1.

Copyright 1996 - 1999, Attachmate Corporation. All rights reserved.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
dvirgint,

what Skip has been trying to point out is that your search string does not specify where to search from:
Code:
Set MyArea = MyScreen.Search("HELLO",[blue]r,c[/blue])
Set rad_find = MyScreen.Search("Radiation par")

also, there's no need for this:
Code:
Loop Until Row = 23

all you need to do is test for where your cursor is after a search. if the cursor returns to 1,1 (see skip's last post, last paragraph), then there is NO other occurrence of your search string.

Try testing from a blank screen, insert "HELLO" in various places on your screen and step through the code and you will see how the code works.

zach
 


If your search is sucessful, it returns an AREA OBJECT, where the TOP property is the ROW and the LEFT property is the COLUMN.

All this stuff is in your documentatin AND it is posted above!!!

Set your NEXT search with ROW+1 until rad_find Is Nothing.

READ & UNDERSTAND the documentation that you have at hand.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Zach,

I did what you said and I can see the cursor move to each of the "HELLO"s, however when it gets to the last one, it stays there, it does not return to 1,1. I have copied your code as it is.

And I appreciate both of you helping... if I don't give the answer you are looking for, it's just that I don't understand what you're asking. I've read through the help file Skip sent several times, but I just don't understand all of what it's saying.

Thanks again.
 


Actually

Set your NEXT search with ROW+1 until rad_find.Top = -1, which is NOT FOUND.

Here's how I did it...
Code:
            Do
                
                Set rad_find = oScrn.Search("Radiation par", rad_find.Top + 1, 1)
                
                If rad_find.Top = -1 Then
                    'GET OUT!
                    Exit Do
                Else
                    MsgBox "found @ " & rad_find.Top
                    'now do some stuff here
                End If
            Loop Until row = 23



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip,

When I changed Set rad_find = oScrn.Search("Radiation par", rad_find.Top + 1, 1), it gave an error 424, Object required, so I dimmed an object for rad_find, but now it gives me an error 424, object variable or with block variable not set.

What am I doing wrong?
 


I had MY screen object, oScrn.

Substitute yours.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Sorry, I have already replaced your screen object for mine, and that's when it gives me the error.
 



Post your code!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top