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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search word in thrid occurance 1

Status
Not open for further replies.

limeg95

Programmer
Oct 22, 2009
124
CA
Skip
I am searching a word 'Total"in report
there are three totals i want only third total with corresponding value this search first total
here is the code
For j = 5 To 41
dfst = Cells(j, 1).Text

if dfst = MyScreen.GetString(1,15,5) then
If dfst <> "" then
do
Set MyArea = MyScreen.Search("Total")
MyScreen.MoveTo MyArea.Bottom, MyArea.Right + 2
MyScreen.Moveto 2, 15
MyRw = MyScreen.Row
Sess0.Screen.Sendkeys("<PF8>")
loop
Next
 
sorry i forgot to add end if
this is full code thanks for looking at.
For j = 5 To 41
dfst = Cells(j, 1).Text

if dfst = MyScreen.GetString(1,15,5) then
If dfst <> "" then
do
Set MyArea = MyScreen.Search("Total")
MyScreen.MoveTo MyArea.Bottom, MyArea.Right + 2
MyScreen.Moveto 2, 15
MyRw = MyScreen.Row
Sess0.Screen.Sendkeys("<PF8>")
loop
end if
end if
Next
 
add a counter

eg: ct = 0
if total found, then ct = ct + 1. when you get ct = 3 you have your 3rd total

i don't understand why you have this
Code:
MyScreen.Moveto 2, 15
 
VZCHIN
thanks will try out and let you know
 
Vzchin
this is the code i have it. where do include counter
totals may be next page
For j = 7 To 48
DSFPT = Cells(j, 1).Text
DSFPT1 = Trim(MyScreen.GetString(6, 9, 6))

If DSFPT <> "" Then

If DSFPT = DSFPT1 Then
MyScreen.Moveto 2, 40
Set MYArea = MyScreen.Search("TOTALS")


MyScreen.Moveto MYArea.Bottom, MYArea.Left
MyRw = MyScreen.Row


If MyRw <> 1 Then

MsgBox (MyRw)

Mytotal1 = Trim(MyScreen.GetString(MyRw, 45, 5))
Mytotal2 = Trim(MyScreen.GetString(MyRw, 64, 12))
Else
MyScreen.SendKeys ("<PF8>")

End If
End If
End If
Next J
 
not knowing your exact setup, try this

Code:
[blue]ct = 0[/blue]
For j = 7 To 48
DSFPT = Cells(j, 1).Text
 DSFPT1 = Trim(MyScreen.GetString(6, 9, 6))
    
     If DSFPT <> "" Then
     
      If DSFPT = DSFPT1 Then
      MyScreen.Moveto 2, 40
    Set MYArea = MyScreen.Search("TOTALS")
           
   
        MyScreen.Moveto MYArea.Bottom, MYArea.Left
        MyRw = MyScreen.Row
        [blue]ct = ct + 1
msgbox ct
        if ct = 3 then
        '3rd Total was found
        end if[/blue]
    
If MyRw <> 1 Then
 
      MsgBox (MyRw)

        Mytotal1 = Trim(MyScreen.GetString(MyRw, 45, 5))
 Mytotal2 = Trim(MyScreen.GetString(MyRw, 64, 12))
  Else
   MyScreen.SendKeys ("<PF8>")
   
          End If
    End If
    End If
Next J
 
vzachin
sometimes it picksup the total sometimes not
becasue totals(3rd time) may be in first page or may in second page
second page should press PF8.
 
try this:
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
        
ct = 0
do
MyScreen.MoveTo 1, 1   'i used this instead of 2,40
Set MyArea = MyScreen.Search("TOTALS")
MyScreen.MoveTo MyArea.Bottom, MyArea.Left  'if Search is success, then 
                                            'move cursor to beginning of string

if MyScreen.row <> 1 and MyScreen.col <> 1 then '1st TOTAL found
ct = ct + 1
msgbox ct
if ct = 3 then exit do
rw = MyScreen.row   'new row pos
col = MyScreen.col  'new col pos
end if


Set MyArea = MyScreen.Search("TOTALS",rw,col + 6)   'start new search at new cursor position
MyScreen.MoveTo MyArea.Bottom, MyArea.Left

if myscreen.row = rw and myscreen.col <> col or _
    myscreen.row <> rw and myscreen.col = col or _
     myscreen.row <> rw and myscreen.col <> col and _
      myscreen.row <> 1 and myscreen.col <> 1  then 
     '2nd TOTAL found
ct = ct + 1
msgbox ct
rw = MyScreen.row   'new row pos
col = MyScreen.col  'new col pos
if ct = 3 then exit do
end if


Set MyArea = MyScreen.Search("TOTALS",rw,col + 6)   'start new search at new cursor position
MyScreen.MoveTo MyArea.Bottom, MyArea.Left 
  
    
if myscreen.row = rw and myscreen.col <> col or _
    myscreen.row <> rw and myscreen.col = col or _
     myscreen.row <> rw and myscreen.col <> col and _
      myscreen.row <> 1 and myscreen.col <> 1  then 
     '3rd TOTAL found
ct = ct + 1
msgbox ct
if ct = 3 then exit do
end if

'if ct <> 3 then
MyScreen.SendKeys ("<PF8>")  'go to next page


loop
 
End Sub

my assumption is that TOTALS can appear 3 times on the first page which is why i did a Search 3 times within the Do/Loop. also, each time TOTALS is found, you need to evoke a new search from where TOTALS is found.
hope this makes sense
 
vzchin
thanks it works if the totals find in first page, some reprots it shows it next page
so do i have to search in next page three times
 
Vzchin
there are so many totals
hwo do search total within "OUTPUT MASTER FILE"
there are so many headings within heading totals are
i need within the header "Output master file" totals

 


So where do you find 'OUTPUT MASTER FILE'?

Is it in a FIXED MESSAGE area or is it in a FIXED TITLE area or is it in a FIXED HEADING area or somewhere else (not fixed) on a screen?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
also, to add to skip's question:
is the TOTALS in a fixed area???
 
skip
it is fixed heading and it not fixed area but normally it comes in second page
 



So this 'OUTPUT MASTER FILE' can appear on ANY screen, ANYWHERE on the screen, in no FIXED ROW or FIXED COLUMN?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
skip
OUTPUT MASTER FILE IS TITLE ROW IS DIFFERENT BUT COLUMN IS 4, 14 IN SECOND PAGE IN THE REPORT

 
limeg95,

since it is a fixed heading, then all you need to do is to first find the heading before looking for the ""TOTALS"...
so the question is:
are you looking for the 3rd TOTALS after the fixed heading "OUTPUT MASTER FILE" ?
the code i provided earlier will loop until ct = 3, which means that the code will page advance to the next page.

you should step through the code to see what it actually does



 



So once you encounter 'OUTPUT MASTER FILE' in column 4 on a sheet, is the VERY NEXT OCCURENCE of 'TOTAL' the one you're after?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 



So FIRST you search for 'OUTPUT MASTER FILE'

Then you begin serch for 'TOTAL'

No counter required.

Skip,

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

Part and Inventory Search

Sponsor

Back
Top