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

waitforstring (test for error)

Status
Not open for further replies.

newbie789

Programmer
Nov 9, 2015
6
US
I have a spreadsheet with 100 account#s. The vba code goes thru each record and puts the account# on the attachmate screen. Then press enter. If account# exists, it goes to next screen. If account# doesn't exist, it stays on the current screen and displays error message. It then captures the error message and puts into Excel and goes to the next record.

This works. But is this the best way to do this?

Sess0.screen.PutString strAcct, 7, 22
Sess0.screen.MoveTo 12, 26
Sess0.screen.SendKeys ("<Enter>")


blnFound = Sess0.screen.waitforstring("_ MAIN MENU")
If blnFound = False Then
'capture error
ActiveCell.Offset(0, 12) = Trim(Sess0.screen.getstring(43, 2, 40))
GoTo MoveToNextRecord
End If
 
Hi,

If it works, then run with it. There is almost always a marginally better way.

However, I'd advise you of one extremely important concept when dealing with a terminal emulator. Once you issue a Command via SendKeys(), it's like arriving at a STOP sign at an intersection in the road. The only way that you know that it's TIME to enter the intersection, is when you observe that no other vehicles will coincide with your vehicle's space as you proceed through the intersection. That is observational feedback. In a similar way, when you send a command to the mainframe from your emulator, the mainframe asynchronously processes the command and then returns the result to the emulator. That might take 1 ms, 1 min, never or anything between. Your code must observe the feedback and WAIT before executing the next statement in your code. Maybe something like...
Code:
Do Until oScrn.WaitForCursor(r, c)
   DoEvents
Loop
...where r,c are the Rest Coordinates for that screen transaction.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
The problem is I don't know where the cursor will land after [Enter].
Let's say cursor is currently at 27, 10 and it has to be here.
Then Enter.
If account is not found, cursor will stay at the same spot and a message will appear at the bottom of the screen.
If account is found, cursor will go to 1,3 on next screen.

I cannot use the below because it might never get there if account doesn't exist.
Do Until oScrn.WaitForCursor(1, 3)
DoEvents
Loop

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top