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!

Macro execution between screens 1

Status
Not open for further replies.

finitesimian

Programmer
Feb 11, 2006
29
US
I am trying to make a script that executes keystrokes/actions based on data visible to a progression of screens, unfortunately my script will not execute some of the actions whenever it progresses to the next screen. I'm probably missing something relatively simple- can you tell me where I'm going wrong?

Code:
Sub Main()
' Get the main system object
  Dim Sessions As Object
  Dim System As Object
  Set System = CreateObject("EXTRA.System")
  Set Sessions = System.Sessions

' Get the necessary Session Object
  Dim Sess0 As Object
  Set Sess0 = System.ActiveSession
  If (Sess0 is Nothing) Then
  STOP
  End If
  If Not Sess0.Visible Then Sess0.Visible = TRUE
  Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'---------------------------------------------------

'obtains data from the first screen and takes action based on data

  Dim variable1 As Object
  Set variable1 = Sess0.Screen.area(row1,col1,row2,col2)
  Select case variable1
      case "something"
         'sends a keystroke which makes it go to the next screen
         Sess0.Screen.Sendkeys("<pf6>")
         'gets data from next screen....this is where my code doesn't want to work
         Dim screen2variable As Object
         Set screen2variable = Sess0.Screen.area(row1,col1,row2,col2)
         'takes action based on data from screen 2
         Select Case screen2variable
         case "something2"
           Sess0.Screen.MoveTo row1,col1
           Sess0,screen.SendKeys("writesomething<Enter>")
           Stop 
         Case "alternative"
           Stop"   
         End Select

      Case "something_else"  
         'takes a different action  
         Sess0.screen.Sendkeys("<pf8>")
         Stop
  
  End Select
End Sub
 
Try taking the row and col out and just leave 1,1,2,2 and then check your variable. It should then have a value.

Set variable1 = Sess0.Screen.area(row1,col1,row2,col2)
 
I wrote it that way just to demonstrate what my code is doing. In reality, it doesn't literally say "row1" and so on.
 
Code:
Sess0.Screen.Sendkeys("<pf6>")
[b]Do you need a wait here? I would guess your code is proceeding before the new screen loads and running into the the case with "Stop".[/b]
Dim screen2variable As Object
 
Use a wait to determine when Extra has finished the last request.

For instance, if the user knows that the word "done" appears at location 2,3 then:
rc% = sess0.screen.waitforstring "done",2,3

You can also leave off the Row/Col and it will look over the whole screen.

calculus
 
One thing you can do if you don't know what data will appear next is something like this:

Code:
Function WaitForScreenChange
    strOld=objScreen.area(1,1,24,80,,3)
    strNew = strOld
    objScreen.SendKeys("<pf6>")
    For i = 0 to 500
        strNew=objScreen.area(1,1,24,80,,3)
        if strOld<>strNew then Exit For
        Do Events
    Next
    If i > 499 then
        objScreen.WaitHostQuiet(1000)
        strNew=objScreen.area(1,1,24,80,,3)
    End If
    WaitForScreenChange = strNew
End Function

This is some code I wrote awhile ago and I'd probably eliminate the for loop and use a timer (for like 5-10 seconds total) using the system time instead. That way faster machines wouldn't hit the WaitHostQuiet as quickly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top