Good day everyone,
I may have mentioned this before, but I am fairly new at AS400 and am trying to get certain script functions to work.
Anyway, I currently connected to 6 different sessions at once, and I have a script to check all of them for system status, however, it breaks if some/all of them are signed out.
How can I use the "If" statement to say "If screen displays Sign In, (Enter credentials) then continue."
Here is my current script. It's a very basic and a simple one, i'm just having trouble getting it to read the screen and then use the if statement.
Sub Main
EMConnect "A"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "B"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "C"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "D"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "E"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "F"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
End Sub
#RumbaHi Erik,
so something onto this?
Sub Main()
MyQSYSOPR "A"
MyQSYSOPR "B"
MyQSYSOPR "C"
MyQSYSOPR "D"
MyQSYSOPR "E"
MyQSYSOPR "F"
End Sub
Sub MyQSYSOPR(ShortName as String)
Dim MyString as String, MyRow as integer, MyCol as integer, RetC as Integer
EMConnect ShortName
'Wait for connection to settle, if physically disconnected from the host
'Note under "Connect" | "Config" ensure that "Prompt On Connect" is not checked.
EMWaitX 1, RetC
'Check to see if we are on the Sign On screen
EMReadScreen MyString, 7, 1, 36
'If yes then logon
If UCase( MyString) = "SIGN ON" then
EMSetCursor 7, 53
EMSendKey "MyMyself"
EMSetCursor 8, 53
EMSendKey "MyPass<Enter>"
'Wait for the Sign-on to complete
EMWaitText 3, "MAIN", 1, 2, MyRow, MyCol
End If
'Check to see if we are already on the "Work with Messages" screen
EMReadScreen MyString,18,1, 32
'If Yes, then send F17 to refresh otherwise locate the cursor and enter the "DSPMSG QSYSOPR" command
If UCase(MyString) = "WORK WITH MESSAGES" then
EMSendKey "<PF17>"
Else
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
End If
End Sub
Good day everyone,
I may have mentioned this before, but I am fairly new at AS400 and am trying to get certain script functions to work.
Anyway, I currently connected to 6 different sessions at once, and I have a script to check all of them for system status, however, it breaks if some/all of them are signed out.
How can I use the "If" statement to say "If screen displays Sign In, (Enter credentials) then continue."
Here is my current script. It's a very basic and a simple one, i'm just having trouble getting it to read the screen and then use the if statement.
Sub Main
EMConnect "A"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "B"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "C"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "D"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "E"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "F"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
End Sub
#RumbaTom,
This is great thank you!
I learned a lot from this and was able to add/modify a bit of it for my needs.
My last thing i'm looking for that I can't seem to get right though....
After it goes through all the connections, I need to only connect to "A" and do the following:
EMConnect "A"
Print "Check"
EMSendKey "<PF3>"
EMSendKey "<ATTENTION>"
EMSetCursor 10, 03
EMSendKey "1<ENTER>"
EMSendKey "21<ENTER>"
EMSendKey "2<ENTER>"
EMSendKey "17<ENTER>"
Print "Check"
EMSendKey "<ATTENTION>"
EMSetCursor 15, 03
EMSendKey "1<ENTER>"
EMSendKey "6<ENTER>"
Print "Check"
EMSendKey "<PF3>"
EMSendKey "<PF3>"
EMSendKey "<PF3>"
EMSendKey "<PF3>"
Thank you in advance.
Good day everyone,
I may have mentioned this before, but I am fairly new at AS400 and am trying to get certain script functions to work.
Anyway, I currently connected to 6 different sessions at once, and I have a script to check all of them for system status, however, it breaks if some/all of them are signed out.
How can I use the "If" statement to say "If screen displays Sign In, (Enter credentials) then continue."
Here is my current script. It's a very basic and a simple one, i'm just having trouble getting it to read the screen and then use the if statement.
Sub Main
EMConnect "A"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "B"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "C"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "D"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "E"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "F"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
End Sub
#RumbaHi Erik,
each time you send an Aid key (i.e. any key which trigger the sending of data to the host, such as an <Enter>, <F5>, <Attn> etc.), you should add a Wait method to allow time for the host to respond and for the terminal to "settle".
So e.g.
EMConnect "A"
EMWaitX 1, RetC
Print "Check"
EMSendKey "<PF3>"
EMWaitX 1, RetC
EMSendKey "<ATTENTION>"
EMWaitX 1, RetC
EMSetCursor 10, 03
EMWaitX 1, RetC
EMSendKey "1<ENTER>"
EMWaitX 1, RetC
EMSendKey "21<ENTER>"
EMWaitX 1, RetC
EMSendKey "2<ENTER>"
EMWaitX 1, RetC
EMSendKey "17<ENTER>"
EMWaitX 1, RetC
Print "Check"
EMSendKey "<ATTENTION>"
EMWaitX 1, RetC
EMSetCursor 15, 03
EMSendKey "1<ENTER>"
EMWaitX 1, RetC
EMSendKey "6<ENTER>"
EMWaitX 1, RetC
Print "Check"
EMSendKey "<PF3>"
EMWaitX 1, RetC
EMSendKey "<PF3>"
EMWaitX 1, RetC
EMSendKey "<PF3>"
EMWaitX 1, RetC
EMSendKey "<PF3>"
EMWaitX 1, RetC
As you only want for this to execute after you have run through sessions "A" through "F", the you can simply leave it in the Sub Main().
Also the RetC can be either a 0 or a 1, if RetC = 1 that indicates the the keyboard was unlocked and the screen is ready to continue. If you get a 0 return code, this indicates that the methods timeout (in this case waiting for the screen to be in a ready start).
There are several EMWait???? methods, you should should which it appropriate for your logic. e.g. above you are sending options to the host e.g. EMSendKey "21<ENTER>", normally one wold need to ensure that the cursor is at the correct position before typing in an option and sending it to the host. So maybe EMWaitForCursor would be more appropriate.
You can checkout the various method in the Script helps, press <F1> while in the script editor.
Note: There is a "Type Ahead" option which one can enable under "Options" | "Edit" "General" tab. Having this turned on or off can have a dramatic effect in the execution of macros, normally I would advise people to turn this off when using automation.
Cheers,
Tom
Good day everyone,
I may have mentioned this before, but I am fairly new at AS400 and am trying to get certain script functions to work.
Anyway, I currently connected to 6 different sessions at once, and I have a script to check all of them for system status, however, it breaks if some/all of them are signed out.
How can I use the "If" statement to say "If screen displays Sign In, (Enter credentials) then continue."
Here is my current script. It's a very basic and a simple one, i'm just having trouble getting it to read the screen and then use the if statement.
Sub Main
EMConnect "A"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "B"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "C"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "D"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "E"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "F"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
End Sub
#RumbaThank you Tom, I didn't realize it was that simple to input it in the Sub Main().
For certain inputs i'm doing such as EMSendKey "21<ENTER>", the cursor is at the default location, and this is simply entering a number to access a sub menu. The cursor cannot be at any other place and input any value.
Is it still good practice to have to have the EMwaitForCursor?
Also, the EMWaitx 1, RetC, you should it's best to let the terminal have time to "settle", is this to prevent the terminal from trying to input the commands too fast and perhaps inputting them at the incorrect place?
Thank you again, you are extremely helpful and knowledgeable.
Good day everyone,
I may have mentioned this before, but I am fairly new at AS400 and am trying to get certain script functions to work.
Anyway, I currently connected to 6 different sessions at once, and I have a script to check all of them for system status, however, it breaks if some/all of them are signed out.
How can I use the "If" statement to say "If screen displays Sign In, (Enter credentials) then continue."
Here is my current script. It's a very basic and a simple one, i'm just having trouble getting it to read the screen and then use the if statement.
Sub Main
EMConnect "A"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "B"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "C"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "D"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "E"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
EMConnect "F"
EMSetCursor 20, 7
EMSendKey "DSPMSG QSYSOPR<Enter>"
End Sub
#RumbaHi Erik,
In general, it is always good practice to have an EMWait method after you send a screen to the host, as Input to the terminal will be blocked until the host answers back and clears the Keyboard lock and Input Inhibited flag on the status line/Operator Information Area (OIA).
You may get away with having no EMWait methods, in fact looking at the operation of the EMSendKey, it appears to have a built-in Wait, which is different to other emulators which I sometimes use. So the Type ahead doesn't appear to have much of an effect, neither does the lack of EMWait methods.
And Yes, invariably the idea behind the "settle" is to wait for the screen to have been completely built and the cursor located at the correct (default) position for that screen. This prevents potentially inputting commands in the incorrect field, or attempting to write into a protected field, which can cause the terminal keyboard to lock as it raises the input inhibit flag. Note: there is an "Auto Reset Keyboard" checkbox just below the "Type Ahead" one (under "Options" | "Edit"), but it's recommended to have this option turned off also for automation.
Cheers,
Tom