Page 1 of 1

[SUGGESTION] If TAG exists

Posted: Thu Jun 10, 2010 1:15 pm
by coolcocky
Dear Danial / Hannes,

I would like to suggest an improvement to imacros, by adding conditional statement which should be easy to implement.

How about adding an "IF TAG.." statement followed with "END IF TAG.." where the statements between both these commands are executed if a particular tag exists otherwise imacros skips it. Also, commands like "ELSE IF TAG" can be incorporated which executes statements when the tag does not exist and if possible you can check suitability of nested ifs also.

This will greatly enhance the suitability of imacros

currently for doing it with scripting we have to send 3 macros to the open imacros window i.e.

1st macro do some work
2nd macro check if tag exists i.e. if tag is found
3rd send macro commands depending on the result of 2nd

and you can of course visualize the scenario where more than one if statements or nested if statements are required based on tag results.

hope this is feasibility for implementation as it increases the utility of imacros by a great extent.

regards,

CooooL

PS: Daniel I have posted source code of Imacros Testing Environment also just have a look

Re: [SUGGESTION] If TAG exists

Posted: Thu Jun 10, 2010 9:38 pm
by LSnelson
I totally agree with this. A simple IF statement would make life easier for us.

Larry

Re: [SUGGESTION] If TAG exists

Posted: Fri Jun 18, 2010 11:27 am
by Daniel, Tech Support
Hi,

Thank you very much for the suggestion! I am sorry for only coming back to you now.

We are thinking of what we can do to add some control flow logic without creating a new complex programming language. And any ideas are very welcome! I will forward this one to our developers now.

Thanks again,

Re: [SUGGESTION] If TAG exists

Posted: Fri Jun 18, 2010 11:27 am
by Daniel, Tech Support
P.S. Thanks for the sources!!

Re: [SUGGESTION] If TAG exists

Posted: Fri Jun 18, 2010 7:42 pm
by coolcocky
@Daniel

I should be the one thanking the whole imacros team for this great software, I have created a couple of bots using c# with imacros and its really easy as compared to doing a bot in c# alone

regards

Re: [SUGGESTION] If TAG exists

Posted: Sat Aug 02, 2014 8:18 pm
by Jonjozz
Use
ActiveDocument.SelectContentControlsByTag("XXXX").Count

if ActiveDocument.SelectContentControlsByTag("XXXX").Count = 0 (There is no Content Control tagged "XXXX")
if ActiveDocument.SelectContentControlsByTag("XXXX").Count = 1 (There is only one Content Control tagged "XXXX")
if ActiveDocument.SelectContentControlsByTag("XXXX").Count = 2 (There are two different Content Control tagged "XXXX")
... and so on.

Re: [SUGGESTION] If TAG exists

Posted: Sat Aug 02, 2014 8:31 pm
by Jonjozz
or then

Dim CC As ContentControls

' Get the collection of all content controls with this tag.
Set CC = ActiveDocument.SelectContentControlsByTag("Thing")

' If any content controls are found iterate through them and give the type.
If CC.Count = 0 Then ‘ The content control tagged "Thing" doesn´t exist.
If CC.Count = 1 Then ‘ There is only one content control tagged "Thing".
If CC.Count = 2 Then ‘ There are 2 different content control tagged "Thing".
… and so on
If CC.Count <> 0 Then ‘The content control tagged "Thing" exists (It could be one or more, but there is at least one Content Control tagged "Thing").