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 strongm 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
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
 


hi,

1. Think in terms of Screen Paging control, without regard to the data on the page. The logic must include

a. how do you detect & respond to an invalid page entry message
b. how do you detect and respond to a more pages for this entry message
c. how do you detect and respond to an end of data message

Your screen control logic should not be included in your screen data processing logic.

2. Now you can develop your screen data processing logic, by looping thru rows on the screen OR by reading the entire screen into a variable and looping thru that data. Either way, this logic is inside and separate from the screen paging logic.



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



btw, here's my basic control structure
Code:
    Const COMP = "LAST PAGE DISPLAYED"
    Const MORE = "MORE DETAIL LINES - PRESS ENTER TO CONTINUE"
    Const NONE = "TRAVELER NOT FOUND ON SERIAL SYSTEM"

    With oScrn
        For Each r In wsPartList.[PART_ID]
            sPn = r.Value
            .Area(3, 17, 3, 33).Value = sPn & "               "
            Do
                .MoveRelative 1, 1, 1
                .SendKeys ("<enter>")
                Do Until (.WaitForCursor(3, 17))
                    DoEvents
                Loop
'
'  screen data stuff occurs in here
'
NextPN:
            Loop Until GetField(sIn, "MSG") = COMP Or GetField(sIn, "MSG") = NONE
        Next
    End With


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks Skip, you always answer quickly and precisely...

I just have no idea what your code does here, it's way beyonf my low level of coding. If you have time, would you mind just telling me briefly what this does?
 


BTW, years ago I developed a generalized approach to screen scraping that writes ALL the data to an Excel Sheet/Table, and that has the following elements.
[tt]
1. A Screen SPEC table that defines: ScrNam, FIELD, FR, TR, CL, LN, TYP;
FR, TR - From Thru row where tabluar screen data resides
If FR=TR then data only on one row
CL - Column
LN - Field Length
TYP - CHAR or NUM

2. Functions that use the screen SPEC, parse the screen data and write them to a table.
[/tt]
To set up a new screen, I load the required data in the Screen SPEC table, do some very slight midifications to a READScreenName procedure, including setting up the Screen Paging CONSTANTS, and a Sheet/Table that contains all FieldNames defined for that screen in the Screen SPEC table. Usually takes about 15 - 20 minutes.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I've modified the above code to created a loop which is supposed to search line by line for the information I need above. My only problem now is that the macro searches the whole screen instead of the delimited area I've determined. How can I get the macro to search only the area I've told it to?

Code:
Set tot_pages = MyScreen.area(1, 66, 1, 68)
Do
        
        line_number = 5
        Set rad_find = Sess0.Screen.Search("Radiation par   ")
        If rad_find <> "Radiation par   " Then
            Sess0.Screen.SendKeys ("<pf8>")    [blue]'This changes the page[/blue]
            Sess0.Screen.WaitHostQuiet (100)
        Else
            Do
                Set n_5 = MyScreen.area(line_number, 2, line_number, 80)   [blue]'This was supposed to tell the macro where to search[/blue]
        
                Set rad_find = [highlight]n_5[/highlight].Search("Radiation par   ")
                If rad_find = "Radiation par   " Then
                    rad_tax_year = n_5.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

If I use Sess0.Screen instead of what is highlighted, the whole screen is searched. Can someone please tell what code to use to accomplish this?

Thanks
Dvirgint
 


How do you know that?

Have you STEPPED THRU your code to observe what is happening? If you code in Excel VBA, you can also use the Watch Window to observe the values in variables and the state of objects in your code.

faq707-4594

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I checked the code step-by-step as suggested, with the help of the Watch, and I can confirm that by using Sess0.Screen.Search the macro searches the whole screen. Each line that was checked had the same result even if the string I was searching for was located on the last line of the page. Thanks for the article by the way Skip, it was very helpful.

If I try to substitute Sess0.Screen.Seach for n_5.Search or n_5.Screen.Search, I get the error Object doesn’t support property or method.

Any suggestions?
 

ExtraHELP 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.
Not the AREA OBJECT.

This Method SEARCHES the ENTIRE SCREEN!

This Method RETURNS the AREA OBJECT.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Please correct me if I'm wrong, but this seems to be saying that this will only search the entire screen - is there another method which will allow a part of the screen to be searched only?
 


WHY?
AREA Object

Description

Provides access to a defined area of the screen.

Properties Methods
Application Copy
Bottom Cut
Left Delete
Parent Paste
Right Select
Top
Type
Value
Comments

You can create Area objects using methods and properties of the Screen object, such as Area and Selection.
Using the methods and properties of an Area object, you can read from or write to the presentation space, an area in PC memory that stores the screen data of a terminal session. A presentation space includes data from the status line (called Operator Information Area in 3270 sessions). Each presentation space position stores a screen character.
To access the presentation space, you must know the exact number of rows and columns that an emulated terminal provides. For example, if a session emulates a terminal supporting 24 rows by 80 columns, you can reference presentation space positions from row 1, column 1 to row 24, column 80. For VT sessions, you can also specify the page.

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


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I need this because I may have more than one instance of the string on a page, and with the Screen object, I get only one of the results, not more.
 


You FIND the first.

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

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Code:
Set rad_find = n_5.Search("Radiation par   ")
Where have you assigned "The row where the search begins"???

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Code:
Set n_5 = MyScreen.area(line_number, 2, line_number, 80)


I thought that this is where I was assigning where it begins?
 

That assigns your n_5 object to that Area.

SO WHAT!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
By your answer, I assume then that I haven't assigned where it begins, and so I have to say that I don't know how to do it.
 

Your search, according the the Extra VB Help, is not at all related to the n_5 Area ovDect that you have assigned.

It is EVERYTHING about the arguments for the Search Method of the SCREEN OBJECT.

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