INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

AS400 Upload Macro PCOMM Script - Variable Loop Question

AS400 Upload Macro PCOMM Script - Variable Loop Question

AS400 Upload Macro PCOMM Script - Variable Loop Question

(OP)
Hello,
I'm OK with VBA in Excel and play a bit with the macros that upload excel data in our ERP system. I've come across one that I'm hoping someone can offer some advice. We have a spreadsheet to upload inventory after a stock take. Our ERP system has a set of keystrokes to enter the data, but on the 14th item, you have to hit page down instead of tab.

So basically I am trying to get the keystrokes to do a set of instructions (TASK A) 13 times, then TASK B on the 14th time, etc. The length of the list could be as short as 35 or as long as 10000 (variable).
TASK A: Do for items 1-13.
TASK B: Do for item 14
TASK A: Do for items 15-27
TASK B: Do for item 28
TASK A: Do for items 29-35

Here is my full code currently, which I can only do 14 items at a time:
[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)
REM This line calls the macro subroutine

Const MK = 0
Const LOC = 1
Const RESOURCE = 2
Const LOT = 3
Const QTY = 4
Const KG = 5
Const QC = 6



Dim i
Dim CorrectRef

Dim BLANKLoad(14)
BLANKLoad(1) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(2) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(3) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(4) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(5) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(6) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(7) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(8) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(9) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(10) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(11) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(12) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(13) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")
BLANKLoad(14) = Array("MK","LOC","RESOURCE","LOT1234567","1","KG","FREE")



subSub1_
sub subSub1_()

i=1
Do While i < UBound(BLANKLoad)+1
autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLPS.SendKeys BLANKLoad(i) (MK)
autECLSession.autECLPS.SendKeys BLANKLoad(i) (LOC)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(i) (RESOURCE)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(i) (LOT)
autECLSession.autECLPS.SendKeys BLANKLoad(i) (QTY)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(i) (KG)
autECLSession.autECLPS.SendKeys BLANKLoad(i) (QC)
autECLSession.autECLPS.SendKeys "    "
autECLSession.autECLPS.SendKeys "    "
autECLSession.autECLPS.Wait 500

i = i + 1
Loop

end sub


TASK A would be this (1-13, 15-27, etc.)
autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLPS.SendKeys BLANKLoad(i) (MK)
autECLSession.autECLPS.SendKeys BLANKLoad(i) (LOC)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(i) (RESOURCE)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(i) (LOT)
autECLSession.autECLPS.SendKeys BLANKLoad(i) (QTY)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(i) (KG)
autECLSession.autECLPS.SendKeys BLANKLoad(i) (QC)
autECLSession.autECLPS.SendKeys "    "
autECLSession.autECLPS.SendKeys "    "
autECLSession.autECLPS.Wait 500

TASK B would be this (14,28,42 etc.) - difference in bold
autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLPS.SendKeys BLANKLoad(i) (MK)
autECLSession.autECLPS.SendKeys BLANKLoad(i) (LOC)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(i) (RESOURCE)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(i) (LOT)
autECLSession.autECLPS.SendKeys BLANKLoad(i) (QTY)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(i) (KG)
autECLSession.autECLPS.SendKeys BLANKLoad(i) (QC)
autECLSession.autECLPS.SendKeys "[page rollup]"
autECLSession.autECLPS.SendKeys "    "
autECLSession.autECLPS.SendKeys "    "
autECLSession.autECLPS.Wait 500

Any advice as this would save hours and hours of time for me! Thanks.

RE: AS400 Upload Macro PCOMM Script - Variable Loop Question

Something like this for a start:

CODE

iMaximum = 100
iCount = 1

Do while iCount <= iMaximum
   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLPS.SendKeys BLANKLoad(i) (MK)
   autECLSession.autECLPS.SendKeys BLANKLoad(i) (LOC)
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLPS.SendKeys BLANKLoad(i) (RESOURCE)
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLPS.SendKeys BLANKLoad(i) (LOT)
   autECLSession.autECLPS.SendKeys BLANKLoad(i) (QTY)
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLPS.SendKeys BLANKLoad(i) (KG)
   autECLSession.autECLPS.SendKeys BLANKLoad(i) (QC)

   If iCount MOD 14 = 0 then
      autECLSession.autECLPS.SendKeys "[page rollup]"
   end if 

   autECLSession.autECLPS.SendKeys "    "
   autECLSession.autECLPS.SendKeys "    "
   autECLSession.autECLPS.Wait 500

   iCount = iCount + 1
Loop 

RE: AS400 Upload Macro PCOMM Script - Variable Loop Question

oops, forgot to increment iCount ... fixed above

RE: AS400 Upload Macro PCOMM Script - Variable Loop Question

(OP)
I had to tweak it a little bit, but the reply got me in the right direction of the "if iCount MOD 14". Here is the final code that worked for me. Thanks for your help!!!

iMaximum = 100
iCount = 1

Do while iCount < UBound(BLANKLoad)+1
autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLPS.SendKeys BLANKLoad(iCount) (MK)
autECLSession.autECLPS.SendKeys BLANKLoad(iCount) (LOC)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(iCount) (RESOURCE)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(iCount) (LOT)
autECLSession.autECLPS.SendKeys BLANKLoad(iCount) (QTY)
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys BLANKLoad(iCount) (KG)
autECLSession.autECLPS.SendKeys BLANKLoad(iCount) (QC)
autECLSession.autECLPS.SendKeys "    "

If iCount MOD 14 = 0 then
autECLSession.autECLPS.SendKeys "[roll up]"
autECLSession.autECLOIA.WaitForAppAvailable


end if

autECLSession.autECLPS.SendKeys "    "
autECLSession.autECLPS.Wait 500

iCount = iCount + 1
Loop

end sub

RE: AS400 Upload Macro PCOMM Script - Variable Loop Question

Glad it helped, thanks for the feedback.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close