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

Use IF statement to loop send key

Status
Not open for further replies.

csilvern12

Technical User
May 4, 2012
8
US
I'm using KEA version 5.10 at work, and it's easy to capture my data to a text file as I've written several macros for excel to format the data for me.

However, I'm brand new to trying to write a macro. My report is easy to run, I just have to keep hitting the enter key after it dsiplays the page to get the next page of data. It's not terrible to do this manually, but sometimes there can be over 200 pages.

Are there any examples of an IF statement, that IF "< Tap Return to Continue, E to exit>" is on the screen, then send the Enter Key until "< Tap Return to Continue >" is on the screen, then end the macro?

I've looked up various do loop statements, and while I can usually modify loops in VBA for excel, I am running out of ideas on how to make it work in KEA. Maybe my problem isn't so easy as to match text and send key, but I sure hope one of you can school me!

 

hi,

WHERE do you expect to "see" "< Tap Return to Continue, E to exit>?

You can use a method like GetString to get the data in that area of the screen, and then TEST that string.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
That part is a little bit tricky, as the line can move around in the bottom half of the screen, depending on how much data appears on the page. The report will spit out between 18 and 21 lines of data per page, and the <Tap Return to Continue, E to Exit> will be on one of these bottom lines.

I'm not sure how I could get the coordinates for where the text normally appears.

Sorry, confidential information and all, replaced by X's to show the screen layout. Y's are variable, sometimes there are two extra lines here that can push the final <Tap> line farther down the screen.

Code:
xxxxxxxxxxx              xxxxxxxx xxx - xxxxxxxx              xxxxxxxxx  xxxxxxxx
                            xxxxx xxxxx xxxx                            Page   x
                              xxxx x xxx

xxx xxxxxx   xxxx  xxxxx  xxxxxxx    xxxxxx                      xxxx
             xxxx   xxxx  xxxxxxx     xxxxx                 xxxx x xxxxxxxxxxx
----------   ----  -----  -------   ---------  -------------------------------------------------
 xxxxxxxx    xxx   xxxxx  xxxx xx   xx xxxxxx  xxxxxx  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  xxxxxx xxxxxxxxxxx  xxxxxxxxx xxxxxx xxxxxx   xxxxxx  xxxxxxxxxxxxxxxxx        

 xxxxxxxx    xxx   xxxxx  xxxx xx   xx xxxxxx  xxxxxx  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  xxxxxx xxxxxxxxxxx  xxxxxxxxx xxxxxx xxxxxx   xxxxxx  xxxxxxxxxxxxxxxxx        
            yyyyy yyyyyyy y                                                 

 xxxxxxxx    xxx   xxxxx  xxxx xx   xx xxxxxx  xxxxxx  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  xxxxxx xxxxxxxxxxx  xxxxxxxxx xxxxxx xxxxxx   xxxxxx  xxxxxxxxxxxxxxxxx      

        < Tap Return to Continue, E to exit> 

xxxxxxxx





 


Good practice for programming screens of this kind, dictates that messages of this kind ALWAYS appear in the same area, like ROW 24, or rows 22-24.

So you're saying that this is NOT the case? Was this screen developed by your IT department or some other way?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Developed a looooong time ago by who knows, very likely the IT dept in some manner or another. I work for a huge company, and this entire software and program is slotted to be replaced in the next few years, so there is zero support for it.

Anyways, yes, the text is very likely to end up in the bottom rows of 18-24, but no guarantees.

When I record my actions, it looks for
Code:
TryMatch( "exit>", MaxTime=100, Idle=IdleTime )
SendKey( "Keypad Enter" )

If there was some way I could loop that continually, it seems like it should work in my head. When I did set it up with a simple loop, my first page of the report has already been displayed when I run the macro, so the text to match never gets "seen".

Sorry if this doesn't make much sense.

 


"but no guarantees"

Then you might as well give up.

LOGIC assumes a guaranteed SOMETHING!

If there is not guarantee that this string will appear in rows 18-24 then what IS guaranteed?

We have to start with SOME KNOWNS!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I have to work on the assumption that the text will appear in the 18-24 lines. If not, then end the macro. Since I'm the only person using it, I would know that I need to finish the report manually. It is only pushing the enter button. :)

I will start doing some searching on this site to see if any GetString and TEST examples will work.
 

i don't know KEA however i do use Attachmate.

in Attachmate, i would simply either look for the string or test each row for the string.

rem
 
I can log in using Attachmate, and maybe that's what I will have to end up doing, but Kea! Attachmate works so much better with this terminal connection.
 
I've tested this bit of code, and it works. It finds the text using the search feature, but I am not sure how to make it loop Until Sess0.Screen.GetString(1, 23, 13) = "Enter Option". Any ideas?

Code:
'Declare Variables
    Dim stringFind As String
    Dim userInput As String
    
    
        
'Set the user input to the string entered in the InputBox
    userInput = "        < Tap Return to Continue, E to exit>"
            
'Start the search for the string
     While stringFind <> userInput
        stringFind = Sess0.Screen.Search(userInput)
        
        If stringFind = userInput Then
        'This is where the select will go
            Sess0.Screen.SendKeys ("<ENTER>")
            'Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
        Else
            
            GoTo NotFound
            
        End If
        
                   
    Wend
        
    MsgBox ("End")
    Exit Sub
    
NotFound:
    MsgBox ("Not Found!")
    Exit Sub

theend:

    End Sub
 
see if this works for you

Code:
'Declare Variables
Dim stringFind As String
Dim userInput As String
'Set the user input to the string entered in the InputBox
userInput = "        < Tap Return to Continue, E to exit>"
'Start the search for the string

[blue]Do[/blue]
    While stringFind <> userInput
        stringFind = Sess0.Screen.Search(userInput)
        If stringFind = userInput Then        'This is where the select will go
            Sess0.Screen.SendKeys ("<ENTER>")
            'Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
        Else
            'GoTo NotFound
            MsgBox ("Not Found!")
            Exit Sub
        End If
    Wend
[blue]Loop Until Sess0.Screen.GetString(1, 23, 13) = "Enter Option"[/blue]

MsgBox ("End")
'Exit Sub
'NotFound:
'MsgBox ("Not Found!")
'Exit Subtheend:
End Sub
 
Thanks Remy, makes sense.

I was working on other projects since this last post, but thought I should come back with my solution. I flipped around the search string and this works like a charm. I can't use this macro with Attachmate Kea!340 (it uses another language that seems very similar, but does not work written as-is) The company I work for has the Attachmate extra locked down pretty well, I can't even select text using their version, but it's not too much of a problem to use it to connect to and run this report.

Code:
' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
	Dim Sessions As Object
	Dim System As Object
	Set System = CreateObject("EXTRA.System")	' Gets the system object
	If (System is Nothing) Then
		Msgbox "Could not create the EXTRA System object.  Stopping macro playback."
		STOP
	End If
	Set Sessions = System.Sessions

	If (Sessions is Nothing) Then
		Msgbox "Could not create the Sessions collection object.  Stopping macro playback."
		STOP
	End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
	g_HostSettleTime = 1000		' milliseconds

	OldSystemTimeout& = System.TimeoutValue
	If (g_HostSettleTime > OldSystemTimeout) Then
		System.TimeoutValue = g_HostSettleTime
	End If

' Get the necessary Session Object
	Dim Sess0 As Object
	Set Sess0 = System.ActiveSession
	If (Sess0 is Nothing) Then
		Msgbox "Could not create the Session object.  Stopping macro playback."
		STOP
	End If
	If Not Sess0.Visible Then Sess0.Visible = TRUE
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	
 
'recorded events ---------------------------------------------------------
 


'Declare Variables
Dim stringFind As String
Dim userInput As String
'Set the user input to the string entered in the InputBox
userInput = "                  < Tap Return to Continue >"
'Start the search for the string

Do
    
    While stringFind <> userInput
        stringFind = Sess0.Screen.Search(userInput)
        If stringFind = userInput Then  'This is where the select will go
        
            Sess0.Screen.SendKeys ("<ENTER>")
            MsgBox ("Complete")
            Exit Sub
                        
        Else
            Sess0.Screen.SendKeys ("<ENTER>")
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
            
        End If
        
        
    Wend
Loop Until Sess0.Screen.GetString(1, 23, 13) = "Enter Option"

MsgBox ("End")

End Sub



 
Err, forgot to remove the extras after loop in my above post (blue).

Code:
Loop [COLOR=blue]'Until Sess0.Screen.GetString(1, 23, 13) = "Enter Option"[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top