Skip to main content

Hello everyone,

 

So while I have been able to use both FOR statements and DO loops successfully, I can't seem to combine them to get my required outcome.

Here is my current script I am using:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"

 

For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Sub
Else
End if
Next i

 End Sub

 

To break it down, I am searching for 3 declared strings and when I do find it, replace number 110 to 215.

The issue I am having, is that I cannot get it to Page Down and continue searching without getting continuous errors and having to force close the script editor.

I have tried wrapping everything in a DO loop, so I can add in the Page Down until it finds it, but while it changes the number from 110 to 215, the script wants to keep running. 

Please tell me if i'm missing something or doing something wrong.

Maybe have things in the wrong spot?

 

Here is how I have it in the DO loop:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"


Do
For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Do
Else
End if
Next i

EMSendkey "<PAGE_DOWN>"

EMReadScreen SEQ, 3, i, 2
If UCase(SEQ) = "215" then
Print "Changed SEQ Successfully"
Exit Do
Else
End if
Loop

End Sub

 

Thank you.


#Rumba

Hello everyone,

 

So while I have been able to use both FOR statements and DO loops successfully, I can't seem to combine them to get my required outcome.

Here is my current script I am using:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"

 

For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Sub
Else
End if
Next i

 End Sub

 

To break it down, I am searching for 3 declared strings and when I do find it, replace number 110 to 215.

The issue I am having, is that I cannot get it to Page Down and continue searching without getting continuous errors and having to force close the script editor.

I have tried wrapping everything in a DO loop, so I can add in the Page Down until it finds it, but while it changes the number from 110 to 215, the script wants to keep running. 

Please tell me if i'm missing something or doing something wrong.

Maybe have things in the wrong spot?

 

Here is how I have it in the DO loop:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"


Do
For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Do
Else
End if
Next i

EMSendkey "<PAGE_DOWN>"

EMReadScreen SEQ, 3, i, 2
If UCase(SEQ) = "215" then
Print "Changed SEQ Successfully"
Exit Do
Else
End if
Loop

End Sub

 

Thank you.


#Rumba
Hi Erik,

you shouldn't need a Do ... loop clause

maybe something like this would do (excuse the pun :-) the trick.

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"

For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
'We have found the row we ere looking for, lets send the 215 and exit.
EMSetCursor i, 2
EMSendkey "215<ENTER>" 'Adding the <ENTER> as I assume you use that to send the update to the host.
Exit Sub 'We have updated the row we can now exit the macro, we can't use
'Exit For
'Exit Sub
'because the Exit Sub will not execute, as we have already exited the For Next loop.
Elseif i = 20 then 'This will only execute if the first if condition is not met..
i = 6 'Resetting i to 6, the next i will add 1 to it to make i = 7
EMSendkey "<PAGE_DOWN>" 'Goto the next page
EMWaitX 1, RetC 'Wait for the next page to appear
End if
Next i

End Sub

Note: The above will remain in the For loop for ever it the row you are looking for it not found. You should really be checking for a string that indicate that you are are the bottom of your list to you can exit if the row you are looking for it never found.

Tom

Hello everyone,

 

So while I have been able to use both FOR statements and DO loops successfully, I can't seem to combine them to get my required outcome.

Here is my current script I am using:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"

 

For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Sub
Else
End if
Next i

 End Sub

 

To break it down, I am searching for 3 declared strings and when I do find it, replace number 110 to 215.

The issue I am having, is that I cannot get it to Page Down and continue searching without getting continuous errors and having to force close the script editor.

I have tried wrapping everything in a DO loop, so I can add in the Page Down until it finds it, but while it changes the number from 110 to 215, the script wants to keep running. 

Please tell me if i'm missing something or doing something wrong.

Maybe have things in the wrong spot?

 

Here is how I have it in the DO loop:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"


Do
For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Do
Else
End if
Next i

EMSendkey "<PAGE_DOWN>"

EMReadScreen SEQ, 3, i, 2
If UCase(SEQ) = "215" then
Print "Changed SEQ Successfully"
Exit Do
Else
End if
Loop

End Sub

 

Thank you.


#Rumba

Wow that is perfect!

I didn't know you could do an Elseif statement!

Thank you Tom for the additional notes as well.
You are always extremely helpful!

 

By the way, is there a way to page down faster?

I do not have the function key for bottom of the page, else I would work my way up since the job is near the bottom and nor can I select which page I want to go to.

I am forced to wait watch the screen page down one at a time.

Normally this would not be an issue as I don't go through many menus with this many pages without having a function key for the bottom, this is a rare instance.


Hello everyone,

 

So while I have been able to use both FOR statements and DO loops successfully, I can't seem to combine them to get my required outcome.

Here is my current script I am using:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"

 

For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Sub
Else
End if
Next i

 End Sub

 

To break it down, I am searching for 3 declared strings and when I do find it, replace number 110 to 215.

The issue I am having, is that I cannot get it to Page Down and continue searching without getting continuous errors and having to force close the script editor.

I have tried wrapping everything in a DO loop, so I can add in the Page Down until it finds it, but while it changes the number from 110 to 215, the script wants to keep running. 

Please tell me if i'm missing something or doing something wrong.

Maybe have things in the wrong spot?

 

Here is how I have it in the DO loop:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"


Do
For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Do
Else
End if
Next i

EMSendkey "<PAGE_DOWN>"

EMReadScreen SEQ, 3, i, 2
If UCase(SEQ) = "215" then
Print "Changed SEQ Successfully"
Exit Do
Else
End if
Loop

End Sub

 

Thank you.


#Rumba

Hi Erik,

maybe you can call up the guy who wrote the host application and pull him out of retirement? :-).

Alternatively you could potentially speed up each iteration of the for routine by changing the If a little

Instead of checking all three fields on each row you could check only on, then one which will have the least false positives.

So instead of

    If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32"

you could check say only for UCase(NUM) = "686-32"

and when you find a match you check the other two, and if they match also then send your 215 and exit.

This would reduce the number of EMReadScreen calls and simplify the If statement a little, thus increasing the exectution speed for each iteration of the For loop (at 14 calls per screen/page if you have a lot of pages it might add up)!!

Another option if the entire row you are looking for always look the same might be to just grab the entire section you are interested in i.e. (7,1) to (20,80) and the do an InStr against if searing for your entire row and then if it's found you can calculate the row which you are looking for

So say row 7, 8 and 9 look like

 100   Hello  Some other fixed string(s) 123-12 ...... Some other fixed strings..AAA..
 110   MER -  Some other fixed string(s) 868-32 ...... Some other fixed strings..BBB..
 123   ByeBye Some other fixed string(s) 111-11 ...... Some other fixed strings..CCC..

You search for " 110   MER -  Some other fixed string(s) 868-32 ...... Some other fixed strings..BBB.."

then if you find a match because you are searching for the entire row you can simple divide the result by the width of the screen (80 by default) and add 7 then you'll have your row number.

This won't reduce the number of page downs, but if might make the for look obsolete and you'd only be doing on EMReadScreen per page, note InStr is a close method, but it should be faster than what it would replace.

The alternative would be to check to see what happen if you increase the screen size, maybe to a MOD4 display or even a Custom size (Mod4 has 43 rows 80 cols) and customer can be even bigger (on my IBM host in a TSO session I can make my screen 62*80). If your application can handle it it may just populate more rows of data, so instead of check between 7 and 20, you may be able to check between 7 and 39 or more. That would reduce the number of pages which you would then need to parse to find what you are looking for.

Alas it's a long shot, but worth giving it a go. There is no easy way around your particular problem

Cheers,
Tom


Hello everyone,

 

So while I have been able to use both FOR statements and DO loops successfully, I can't seem to combine them to get my required outcome.

Here is my current script I am using:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"

 

For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Sub
Else
End if
Next i

 End Sub

 

To break it down, I am searching for 3 declared strings and when I do find it, replace number 110 to 215.

The issue I am having, is that I cannot get it to Page Down and continue searching without getting continuous errors and having to force close the script editor.

I have tried wrapping everything in a DO loop, so I can add in the Page Down until it finds it, but while it changes the number from 110 to 215, the script wants to keep running. 

Please tell me if i'm missing something or doing something wrong.

Maybe have things in the wrong spot?

 

Here is how I have it in the DO loop:

Sub Main
Dim RetC as Integer, SEQ as String, JOB as String, NUM as String
EMConnect "A"
SysHide "Timer"


Do
For i = 7 to 20
EMReadScreen SEQ, 3, i, 2
EMReadScreen JOB, 6, i, 7
EMReadScreen NUM, 6, i, 49
If UCase(SEQ) = "110" and UCase(JOB) = "MER - " and UCase(NUM) = "686-32" then
EMSetCursor i, 2
EMWaitX 1, RetC
EMSendkey "215"
EMWaitX 1, RetC
Exit for
Exit Do
Else
End if
Next i

EMSendkey "<PAGE_DOWN>"

EMReadScreen SEQ, 3, i, 2
If UCase(SEQ) = "215" then
Print "Changed SEQ Successfully"
Exit Do
Else
End if
Loop

End Sub

 

Thank you.


#Rumba
Hello Tom,

Thank you for all the suggestions!

While I am unsure of how to use the "InStr" method, or how/if I could increase my screen size since I have never tried them before, but thanks to one of your other suggestions I was able to get it to page down dramatically faster!

As you said, I had it only for look for one string, which was "More".
So I had it continually search and see if it had "More" pages until it hit the bottom, then I worked my way up.
This worked exceedingly well seeing as what I needed was towards the bottom anyway.

Again, thank you for all your help Tom!