try/catch in COM Interface calls not working in PMC (workaround)

Advanced Macro Recorder/Editor.

Moderator: Pulover

aircooled
Posts: 80
Joined: 01 Dec 2018, 08:51

try/catch in COM Interface calls not working in PMC (workaround)

21 Jan 2020, 09:58

This scenario involves several COM Interface Excel calls that were a little tricky to solve. I have solved it and it works but the solution is not so straight forward.

I would like to know if the COM Interface editor in Pulover Macro Creator can be setup to avoid this situation.

I have a loop that calls Excel 10 times through COM Interface. When the loop is executed many times it results in a lot of COM Interface calls.

Normally it works very well but randomly one of the COM Interface Excel calls return an error, “Excel didn’t respond” or other errors. I added a lot of delays up to 1200-1500ms per COM Interface call and it improved a lot but still I got some errors maybe 1 in 30-50 calls. However it was clear that so many calls in a short time span were the problem. Executing the same COM Interface call (that failed) right after a few ms responded just fine.

So I have added a “try/catch” statement to each one of the COM Interface calls. That solved the problem. If an error is catched then the call is repeated after 10ms or so and it works well.
At runtime I can observe that it loops very fast through the Excel cells and now and then stays a little bit longer in one cell: the call failed and was repeated there.

I have been able to reduce the delays between COM Interface calls from 1200-1500ms to 10 ms and it works perfect.

BUT HERE COMES THE ISSUE.
I surround each COM Interface call with a try/catch statement and hit OK.

https://postimg.cc/RWJyZyJv/ba6ca74e

https://postimg.cc/mzLmC5kz

The problem is that in PMC the new lines are written as `n in the code. This is what I see in PMC:

https://postimg.cc/dZTNVTD4

and this doesn’t work it isn’t accepted by PMC and the execution of the COM Interface call does nothing. If I remove the try/catch and have just the COM Interface call it works fine.
(Could all the try/catch logic be written in a single line without new line breaks?)
So export the code to AHK, replace all `n with a ‘Manual Line Break’ in Word and the code works perfectly.

https://postimg.cc/6TLYYwn7

The whole execution elapses now in less time that it took for one (1) single COM Interface call before due to the ridiculous large delays I had.

How can PMC be setup in order for it to parse the try/catch statements correctly as valid code.

The `n new line markers causing problem here. Thanks
User avatar
Pulover
Posts: 612
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: try/catch in COM Interface calls not working in PMC (workaround)

17 Sep 2020, 05:43

Actually, loop, try and catch are commands and cannot be used inside expressions. I don't even know how this would be evaluated. The Expressions window accepts expressions only. You cannot simply paste any ahk script in there.

Maybe I can add try/catch statements in a future version, but this is not supported at the moment.

You can prevent the error messages if it is of any help for you. https://www.macrocreator.com/docs/Faq.html#how-can-i-avoid/bypass-error-messages-during-playback
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)

Return to “Pulovers Macro Creator”

Who is online

Users browsing this forum: No registered users and 74 guests