Link to home
Start Free TrialLog in
Avatar of jim25
jim25

asked on

Script Problem

Hi all

Not sure if this is the right place to post but I am using an IBM program with the following macro I have recorded (see below). The problem I am having is that the macro is not pasting in the 5 digit number i have originally copied. Any ideas how to fix this? Cheers.

[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)

REM This line calls the macro subroutine
subSub1_

sub subSub1_()
   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[left]"
   autECLMacro "[mark left]"

   autECLMacro "[mark left]"

   autECLMacro "[mark left]"

   autECLMacro "[mark left]"

   autECLMacro "[mark left]"

   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 5,13,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 5,14,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "ClearingZeropay"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "ClearingZeroPayValue"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "x"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "x"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 9,7,"10","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 9,8,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf3]"
   
   autECLSession.autECLPS.WaitForAttrib 5,13,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf1]"
   
   autECLSession.autECLPS.WaitForAttrib 4,18,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf12]"
   
   autECLSession.autECLPS.WaitForAttrib 17,32,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 17,33,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "2"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 4,18,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 5,13,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 5,14,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "ClearingZeroPAy"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "ClearingZeroPayment"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "x"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "x"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 9,7,"10","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 9,8,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf3]"
   
   autECLSession.autECLPS.WaitForAttrib 5,13,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf1]"
   
   autECLSession.autECLPS.WaitForAttrib 4,18,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf12]"
   
   autECLSession.autECLPS.WaitForAttrib 17,32,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf24]"
   
   autECLSession.autECLPS.WaitForAttrib 22,6,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 22,7,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "7"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 4,18,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 7,63,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 7,64,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "xx"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf1]"
   
   autECLSession.autECLPS.WaitForAttrib 8,13,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 8,14,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "contra"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "d"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 8,13,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf1]"
   
   autECLSession.autECLPS.WaitForAttrib 4,18,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf24]"
end sub
Avatar of mvidas
mvidas
Flag of United States of America image

Jim,

When have you copied the number to the clipboard? What was the number you used for the recording of this macro?

There is an AS/400 topic area, and daveslater there knows a lot about this too, but since you're using the vbscript macro capability I think you're fine where you posted it.  It could have gone in as400, vb, programming, or programming languages, but as long as you get an answer, it doesnt matter that much where it goes.

You may want to consider 'cleaning up' the recorded code there.  A lot of it involves using sendkeys and tabbing to new fields, so a bit of manual work will be involved.  In my as400 scripts, I have a couple functions I always use to make things a little easier.

The most used one I have is:
'Inserts text 'txt' at row 'rw' and column 'cl'
Function PutText(rw, cl, txt, autECLSession)
 WaitInpApp autECLSession '200
 autECLSession.autECLPS.SetCursorPos rw, cl
 autECLSession.autECLPS.SendKeys "[eraseeof]"
 autECLSession.autECLPS.SendKeys txt
End Function

Send it the coordinates and text (and session, usually just 'autECLSession'), and it will put the text on that portion of the screen.  Makes for more precise text entry, helpful if fields could be added to specific screens.

Another one I like to use can replace a lot of the groups that look like:
   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLOIA.WaitForInputReady

I just have one function for it:

Function WaitInpApp(autECLSession)
 autECLSession.autECLOIA.WaitForAppAvailable
 autECLSession.autECLOIA.WaitForInputReady
 Do Until autECLSession.autECLOIA.InputInhibited = 0
  autECLSession.autECLOIA.WaitForInputReady
  autECLSession.autECLOIA.WaitForAppAvailable
 Loop
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLOIA.WaitForAppAvailable
 Do While autECLSession.Ready = False
  autECLSession.autECLOIA.WaitForInputReady
  autECLSession.autECLOIA.WaitForAppAvailable
 Loop
End Function

Here are some of the others I might use in a script, with comments above the declaration line:

'Presses enter
Function PressEnter(autECLSession)
 autECLSession.autECLPS.SendKeys "[enter]"
End Function

'waits for a specific text string on screen to continue
Function lookText(inptText, autECLSession)
 Dim bln
 bln = autECLSession.autECLPS.WaitForString(inptText)
 Set bln = Nothing
End Function

'gets text at row x, column y, length z
Function gety(x, y, z, autECLSession)
 gety = autECLSession.autECLPS.GetText(x, y, z)
 Set x = Nothing
 Set y = Nothing
 Set z = Nothing
End Function

But as I asked originally, where do you get your 5 digit number from, and what was it for the recorded session?
Matt
Avatar of jim25
jim25

ASKER

Hi MAtt

Thanks for your reply! I orginally got the 5 digit number from my input. To be honest I can not remember the number I used.

My thinking was that I could manually type in the number and then run the macro telling it to copy the inputted number and paste it into certain required fields later but it could not do it!

Any ideas why?
Not sure exactly what you mean, in all honesty.. a better way to do it would be to create a variable for it.. add the following two lines after the "Sub subSub1_()" line:

Sub subSub1_()
   Dim TheNum
   TheNum = InputBox("Please input 5 digit number")

Then later on just refer to 'TheNum' when text is sent, like:
   autECLSession.autECLPS.SendKeys TheNum

Or, if you're using my function
   PutText 7, 53, TheNum, autECLSession

etc..
As far as the previous recording goes, the only 5 character string that I saw was the repeated "01.00" .. could that have been it?
Matt
Avatar of jim25

ASKER

Hi Matt

Thanks again for your response! Looking at the script it seems to me that while recording the macro it did not actually the copy function!


autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[left]"
   autECLMacro "[mark left]"

   autECLMacro "[mark left]"

   autECLMacro "[mark left]"

   autECLMacro "[mark left]"

   autECLMacro "[mark left]"

AFTER this section the hightlight area SHOULD have been copied to the clipboard but it does not seem to have done that!

   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"

What would you suggest is the best way of getting around this problem?

Many thanks again Matt
Hi jim,

Sorry for the delay, I was out from work yesterday and my laptop died on Friday.

I've never used the Mark Left like that, I'm guessing that is to select a portion of the screen for copying.  When I have to get something from the screen, I use the gety function I showed you in http:Q_21686380.html#15632141 and save the contents to a variable.  So lets say I want to get a 5 digit number from my screen.  
First off, figure out the coordinates the number is at.  When you're on the screen that contains that number, click the mouse once at the first number you want to get (of the 5).  Look in the bottom right of the screen and you'll see that position's coordinates (like 06/066), you'll need those for the function.  In your main subroutine, you'll need to create a variable, like

 Dim fivedigitnum

Then you'll need to assign the function output to that variable, like

 fivedigitnum = gety(6, 66, 5, autECLSession)

Then when you need to put that text somewhere, you can use the PutText function I also posted above.  Say you had to put the number at coordinates 12/042:

 PutText 12, 42, fivedigitnum, autECLSession

Does that make sense?  You're storing the number to a variable, then using that variable later on to put text on the screen.  You're not actually copying it to the clipboard, rather to temporary memory for this script.  

Please let me know if you have any questions! I'd help whittle your above code down to something short, but without knowing the coordinates to do things I wouldn't really be much help.. I can try though, I can write it out generically then you can fill in where things go, if that might help..

Matt
Avatar of jim25

ASKER

Hi Matt

Thanks again for your post. Ok I think we are making progress. I have the coordinates I need to get the 5 digit number:04/019

Dim fivedigitnum

fivedigitnum= gety(4, 19, 5 autECLSession)

Where do I put this function? At the top of the script and call it later?

Function PutText(rw, cl, txt, autECLSession)
 WaitInpApp autECLSession '200
 autECLSession.autECLPS.SetCursorPos rw, cl
 autECLSession.autECLPS.SendKeys "[eraseeof]"
 autECLSession.autECLPS.SendKeys txt
End Function

I always put functions at the end, just as thats how I do it.  The way your vbscript is currently setup is (without actual code):

'your [HEADERS] are at the top

'your "main" code is here
autECLSession.SetConnectionByName(ThisSessionName)
subSub1_ 'calls the subroutine

sub subSub1_()
 'your subSub1_ subroutine
end sub

function gety(....)

end function
function puttext(....)

end function


I'd say set it up like this, then you can call the functions as needed.

Since you don't have a real overly complicated routine, you could probably eliminate the autECLSession as an argument to send the function, I just had to do it that way for memory reasons (long long story).
Also, since you probably aren't adding the 'WaitInpApp' function I pasted above, you could use the following instead for your functions (removed call to WaitInpApp and removed autECLSession as a function argument):

Function gety(x, y, z)
 gety = autECLSession.autECLPS.GetText(x, y, z)
 Set x = Nothing
 Set y = Nothing
 Set z = Nothing
End Function
Function PutText(rw, cl, txt)
 autECLSession.autECLOIA.WaitForAppAvailable
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SetCursorPos rw, cl
 autECLSession.autECLPS.SendKeys "[eraseeof]"
 autECLSession.autECLPS.SendKeys txt
End Function

You would just need to call it like:
 fivedigitnum= gety(4, 19, 5)

Let me know what else I can do to help!
Matt
Avatar of jim25

ASKER

I am trying to run this macro but it is not working can you help Matt?

[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)
subSub1_

sub subSub1_()

Dim=fivedigitnumber

fivedigitnum= gety(4, 19, 5 autECLSession)

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf12]"
   
   autECLSession.autECLPS.WaitForAttrib 17,32,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 17,33,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "1"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"

PutText 4, 19, fivedigitnum, autECLSession
end sub

Function gety(x, y, z, autECLSession)
 gety = autECLSession.autECLPS.GetText(x, y, z)
 Set x = Nothing
 Set y = Nothing
 Set z = Nothing
End Function

Function PutText(rw, cl, txt)
 autECLSession.autECLOIA.WaitForAppAvailable
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SetCursorPos rw, cl
 autECLSession.autECLPS.SendKeys "[eraseeof]"
 autECLSession.autECLPS.SendKeys txt
End Function
Sure, getting there, couple minor things..

 Dim=fivedigitnumber
should be
 Dim fivedigitnumber

Also, in one of my comments I had removed the session variable as an argument from PutText, so you can also change

 PutText 4, 19, fivedigitnum, autECLSession
to
 PutText 4, 19, fivedigitnumber

That should do it!
Avatar of jim25

ASKER


Comes up with an error on line 13 saying that a ')' is expected. Any ideas?

[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)
subSub1_

sub subSub1_()

Dim fivedigitnumber

fivedigitnum= gety(4, 19, 5 autECLSession))

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf12]"
   
   autECLSession.autECLPS.WaitForAttrib 17,32,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 17,33,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "1"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"

PutText 4, 19, fivedigitnum,
end sub

Function gety(x, y, z, autECLSession)
 gety = autECLSession.autECLPS.GetText(x, y, z)
 Set x = Nothing
 Set y = Nothing
 Set z = Nothing
End Function

Function PutText(rw, cl, txt)
 autECLSession.autECLOIA.WaitForAppAvailable
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SetCursorPos rw, cl
 autECLSession.autECLPS.SendKeys "[eraseeof]"
 autECLSession.autECLPS.SendKeys txt
End Function

ASKER CERTIFIED SOLUTION
Avatar of mvidas
mvidas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jim25

ASKER

Matt you are a genius!!!!! Thanks so much! I have got the following macro to work:

[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]

OPTION EXPLICIT
 autECLSession.SetConnectionByName (ThisSessionName)
 subSub1_

Sub subSub1_()
 Dim fivedigitnumber
 fivedigitnumber = gety(4, 19, 5)
 autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 5,13,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 5,14,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "Clearingzeropay"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "Clearing Zero Payment"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "x"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "x"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 9,7,"10","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 9,8,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf3]"
   
   autECLSession.autECLPS.WaitForAttrib 5,13,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf1]"
   
   autECLSession.autECLPS.WaitForAttrib 4,18,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf12]"
   
   autECLSession.autECLPS.WaitForAttrib 17,32,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 17,33,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "2"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
 PutText 4, 19, fivedigitnumber
autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 5,13,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 5,14,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "ClearingZEROPAy"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "Clearing Zero Payment"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "x"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "x"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 9,7,"10","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 9,8,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "01.00"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf3]"
   
   autECLSession.autECLPS.WaitForAttrib 5,13,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf1]"
   
   autECLSession.autECLPS.WaitForAttrib 4,18,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf12]"
   
   autECLSession.autECLPS.WaitForAttrib 17,32,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf24]"
   
   autECLSession.autECLPS.WaitForAttrib 22,6,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 22,7,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "7"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
PutText 4, 19, fivedigitnumber
autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 7,63,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 7,64,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "xx"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 7,63,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf1]"
   
   autECLSession.autECLPS.WaitForAttrib 8,13,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 8,14,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "Contra"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "d"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 8,13,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf1]"
   
   autECLSession.autECLPS.WaitForAttrib 4,18,"00","3c",3,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf24]"
End Sub

Function gety(x, y, z)
 gety = autECLSession.autECLPS.GetText(x, y, z)
 Set x = Nothing
 Set y = Nothing
 Set z = Nothing
End Function

Function PutText(rw, cl, txt)
 autECLSession.autECLOIA.WaitForAppAvailable
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SetCursorPos rw, cl
 autECLSession.autECLPS.SendKeys "[eraseeof]"
 autECLSession.autECLPS.SendKeys txt
End Function

Brilliant! Thanks sooooooooo much. It will save me sh*t loads of time. Cheers!
Avatar of jim25

ASKER

Matt is it possible to tidy my final code up because it runs a bit slow? Cheers!
Gladly! I'll show you what it is I'm doing as well, so you can make new macros and make them faster/cleaner using the same ideas


First off, I pretty much get rid of any "Wait______" methods, except for WaitForAppAvailable and WaitForInputReady.  

So I delete lines like
 autECLSession.autECLPS.WaitForAttrib 5, 13, "00", "3c", 3, 10000
and
 autECLSession.autECLPS.WaitForCursor 5, 14, 10000

I'll admit I don't exactly know what attributes are what, but I've never had an issue removing lines like that from recorded code.


I also get rid of blank lines, generally, unless different sections of the code do completely different things (or I need part of it to stand out, if i were working on part of it, so i know where i left off).  I usually leave a blank line between the top and the subs/functions/etc too, just for readability.

So far doing all that I've cut it down from 246 lines to 161.


Next, looking at the code, you'll see many instances where the following two lines appear next to each other:

 autECLSession.autECLOIA.WaitForAppAvailable
 autECLSession.autECLOIA.WaitForInputReady

Always in the same order.  When I see code repeating like that, I think 'why not have a function that does that, so theres only one line of code in the main section instead?'

So I add the following to the end of the whole code:

Function WaitInputApp()
 autECLSession.autECLOIA.WaitForAppAvailable
 autECLSession.autECLOIA.WaitForInputReady
End Function

Then replace every instance of the above two lines with
 WaitInputApp

Down to 145 lines now


After doing that, there are a lot of instances where the following Wait line is by itself:
 autECLSession.autECLOIA.WaitForInputReady

That is usually necessary after switching screens (pressing enter or an F-key), but not after normal text by itself.  So the long blocks like:
 autECLSession.autECLPS.SendKeys "ClearingZEROPAy"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
(continues much longer as well without switching screens)

This can be shortened a lot as well, though for this I'll need to you do some work as well.

The [tab] lines are when you're changing fields, so we can get rid of these once you know where the text before/after goes (by the coordinates).  I can do some preliminary work shortening this, but you can speed it up a lot after I'm done.

As an example, near the beginning is this huge block of code:

 autECLSession.autECLPS.SendKeys "Clearingzeropay"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "01.00"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "Clearing Zero Payment"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "x"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "01.00"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "[tab]"
 autECLSession.autECLOIA.WaitForInputReady
 autECLSession.autECLPS.SendKeys "x"
 autECLSession.autECLOIA.WaitForInputReady

Since you dont really need the WaitForInputReady here (not switching screens), it can be shortened to:
 autECLSession.autECLPS.SendKeys "Clearingzeropay"
 autECLSession.autECLPS.SendKeys "[tab][tab][tab]" & "01.00"
 autECLSession.autECLPS.SendKeys "[tab]" & "Clearing Zero Payment"
 autECLSession.autECLPS.SendKeys "[tab]" & "x"
 autECLSession.autECLPS.SendKeys "[tab]" & "01.00"
 autECLSession.autECLPS.SendKeys "[tab][tab]" & "x"

I'll leave you to shorten that further, if you see fit, by changing each of those lines to use the coordinates with PutText.  There will be many more instances like this, but at least it will still be usable the way I give it to you.  Shortening these to PutText will make it much easier for you in the future as well, if you have to debug it, add something, or change something to accommodate a changing menu.  Plus you can get rid of all the [tab] portions :)


Another little thing is when your code is pressing a function key, like:
 WaitInputApp
 autECLSession.autECLPS.SendKeys "[pf1]"

It can be knocked down a little to:
 PutText 1, 1, "[pf1]"

I put 1,1 for the coordinates, since it shouldnt really make a difference where the blinking cursor is when you hit F1.


After just shortening the whole code, I see the following block twice:

 autECLSession.autECLPS.SendKeys "Clearingzeropay"
 autECLSession.autECLPS.SendKeys "[tab][tab][tab]" & "01.00"
 autECLSession.autECLPS.SendKeys "[tab]" & "Clearing Zero Payment"
 autECLSession.autECLPS.SendKeys "[tab]" & "x"
 autECLSession.autECLPS.SendKeys "[tab]" & "01.00"
 autECLSession.autECLPS.SendKeys "[tab][tab]" & "x[enter]"
 WaitInputApp
 autECLSession.autECLPS.SendKeys "01.00[field+]"
 PutText 1, 1, "[pf3]"
 PutText 1, 1, "[pf1]"

I don't know if it will stay exactly the same after you check the coordinates for each line being entered, but if it does stay the same I'd recommend creating a function that enters this for you.  Shorten the code, make it easier to read and should be a little more efficient.


Also, though it makes no real difference, I'm changing the name of the main subroutine from "subSub1_" to "MainSubroutine"


So, after all that (you can still shrink it more), I'm at 65 lines now.  And after you update this to include coordinates, it'll be even shorter.  But heres how it is currently:

[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
Option Explicit
 autECLSession.SetConnectionByName ThisSessionName
 MainSubroutine

Sub MainSubroutine()
 Dim FiveDigitNumber
 FiveDigitNumber = GetSomeText(4, 19, 5)
 PutText 1, 1, "[enter]"
 autECLSession.autECLPS.SendKeys "Clearingzeropay"
 autECLSession.autECLPS.SendKeys "[tab][tab][tab]" & "01.00"
 autECLSession.autECLPS.SendKeys "[tab]" & "Clearing Zero Payment"
 autECLSession.autECLPS.SendKeys "[tab]" & "x"
 autECLSession.autECLPS.SendKeys "[tab]" & "01.00"
 autECLSession.autECLPS.SendKeys "[tab][tab]" & "x[enter]"
 WaitInputApp
 autECLSession.autECLPS.SendKeys "01.00[field+]"
 PutText 1, 1, "[pf3]"
 PutText 1, 1, "[pf1]"
 PutText 1, 1, "[pf12]"
 WaitInputApp
 autECLSession.autECLPS.SendKeys "2[enter]"
 PutText 4, 19, FiveDigitNumber & "[enter]"
 autECLSession.autECLPS.SendKeys "ClearingZEROPay"
 autECLSession.autECLPS.SendKeys "[tab][tab][tab]" & "01.00"
 autECLSession.autECLPS.SendKeys "[tab]" & "Clearing Zero Payment"
 autECLSession.autECLPS.SendKeys "[tab]" & "x"
 autECLSession.autECLPS.SendKeys "[tab]" & "01.00"
 autECLSession.autECLPS.SendKeys "[tab][tab]" & "x[enter]"
 WaitInputApp
 autECLSession.autECLPS.SendKeys "01.00" & "[field+]"
 PutText 1, 1, "[pf3]"
 PutText 1, 1, "[pf1]"
 PutText 1, 1, "[pf12]"
 PutText 1, 1, "[pf24]"
 WaitInputApp
 autECLSession.autECLPS.SendKeys "7[enter]"
 PutText 4, 19, FiveDigitNumber & "[enter]"
 autECLSession.autECLPS.SendKeys "xx[enter]"
 PutText 1, 1, "[pf1]"
 WaitInputApp
 autECLSession.autECLPS.SendKeys "Contra"
 autECLSession.autECLPS.SendKeys "[tab]" & "d[enter]"
 PutText 1, 1, "[pf1]"
 PutText 1, 1, "[pf24]"
End Sub
Function GetSomeText(rw, cl, lngth)
 GetSomeText = autECLSession.autECLPS.GetText(rw, cl, lngth)
 Set rw = Nothing
 Set cl = Nothing
 Set lngth = Nothing
End Function
Function PutText(rw, cl, txt)
 WaitInputApp
 autECLSession.autECLPS.SetCursorPos rw, cl
 autECLSession.autECLPS.SendKeys "[eraseeof]"
 autECLSession.autECLPS.SendKeys txt
End Function
Function WaitInputApp()
 autECLSession.autECLOIA.WaitForAppAvailable
 autECLSession.autECLOIA.WaitForInputReady
End Function

You'll probably have noticed I changed the name of "gety" to "GetSomeText", as "gety" didnt really describe what it does (makes sense to me, but this isn't for me now).  

Also, if you change all the "...SendKeys..." lines to "PutText r, c, text", you can remove all the "WaitInputApp" lines in the MainSubroutine as well (since PutText has a WaitInputApp at the beginning).  
Once you get all the coordinates you need, your MainSubroutine will look like:

Sub MainSubroutine()
 Dim FiveDigitNumber
 FiveDigitNumber = GetSomeText(4, 19, 5)
 PutText 1, 1, "[enter]"
 PutText rw, cl, "Clearingzeropay"
 PutText rw, cl, "01.00"
 PutText rw, cl, "Clearing Zero Payment"
 PutText rw, cl, "x"
 PutText rw, cl, "01.00"
 PutText rw, cl, "x[enter]"
 PutText rw, cl, "01.00[field+]"
 PutText 1, 1, "[pf3]"
 PutText 1, 1, "[pf1]"
 PutText 1, 1, "[pf12]"
 PutText rw, cl, "2[enter]"
 PutText 4, 19, FiveDigitNumber & "[enter]"
 PutText rw, cl, "ClearingZEROPay"
 PutText rw, cl, "01.00"
 PutText rw, cl, "Clearing Zero Payment"
 PutText rw, cl, "x"
 PutText rw, cl, "01.00"
 PutText rw, cl, "x[enter]"
 PutText rw, cl, "01.00[field+]"
 PutText 1, 1, "[pf3]"
 PutText 1, 1, "[pf1]"
 PutText 1, 1, "[pf12]"
 PutText 1, 1, "[pf24]"
 PutText rw, cl, "7[enter]"
 PutText 4, 19, FiveDigitNumber & "[enter]"
 PutText rw, cl, "xx[enter]"
 PutText 1, 1, "[pf1]"
 PutText rw, cl, "Contra"
 PutText rw, cl, "d[enter]"
 PutText 1, 1, "[pf1]"
 PutText 1, 1, "[pf24]"
End Sub

Looking at it like that helps you see exactly what the macro is doing (so hopefully if someone else needed to look at this, they'd understand what its doing).  Plus hopefully this can help you design/streamline future scripts as well :)

Hope this helps! If you need any help in the future, you won't be able to leave another comment on this question.  If I'm still around to help, I'll have my email address in my profile, so you can email me a link to any new questions you post (using "Send to a friend" at the top of a new question thread)
Matt