If and goto

Questions, comments, and suggestions related to Typeitin.
Post Reply
BarneyEuropa
Posts: 3
Joined: Tue Feb 26, 2019 4:01 pm

If and goto

Post by BarneyEuropa » Tue Feb 26, 2019 4:45 pm

A friendly "Hi all",

I am not really a "coder".

Though I try to compose a macro, that tests if a certain line of a text contains "A1abc" or "B1abc" or "C1abc"

If Yes I want to replace "A1abc" by "A2abc", "B1abc" by "B2abc" and "C1abc" by "C2abc".

If not I want to continue the macro at a label "Continue" without a replacing procedure.

First, I don't know whether I can use an "OR"-function e.g. if I can search for "A1abc" and "B1abc" simultaneously.

Second I can't manage to combine {If... with {Goto... successfully

This forum doesn't contain older topics where I could learn from other examples.

So I tried this:
At first the line is found and marked and copied to the clipboard
Then I wrote to the macro:

Code: Select all

{Var15 GetClip}{If (Var15=A1*) {Goto ReplaceA1} Else {Goto Continue}}

{Label ReplaceA1}

{Var15 Replace A1|A2}{Delay 100}

{***--- now the marco finds the certain line again and marks it---***}

{Var15}
{*** this will replace the line and "A1abc" should now be replaced by "A2abc"---actually this works!***}

{Label Continue}
{Paste nothing was replaced} 
But: that doesn't work!
The macro doesn't go to the labels because the "goto" doesn't seem to work with "if".
At least I don't know the right syntax and couldn't find a matching example in the help-file.

Can anybody help me?

Wavget
Site Admin
Posts: 91
Joined: Wed Jan 16, 2019 4:32 pm

Re: If and goto

Post by Wavget » Wed Feb 27, 2019 10:13 am

There are some missing brackets in the If/Else statement:

{Var15 GetClip}{If (Var15=A1*) [{Goto ReplaceA1}] Else [{Goto Continue}]}

Also, after a replacement is done, you should jump over the Nothing replaced section to skip to the end.

This is the corrected code:

{Var15 GetClip}{If (Var15=A1*) [{Goto ReplaceA1}] Else [{Goto Continue}]}

{Label ReplaceA1}
{Var15 Replace A1|A2}{Delay 100}
{Var15}
{GoTo End}

{Label Continue}
{Dialog 0,Information,[Ok],Nothing replaced!}

{Label End}


Not sure if this would be helpful, but you can use {Ctrl c} to copy highlighted text to the clipboard. If you put that before the {Var15 GetClip} you can highlight text and then click the button.

Hope this helps,
Paul.

BarneyEuropa
Posts: 3
Joined: Tue Feb 26, 2019 4:01 pm

Re: If and goto

Post by BarneyEuropa » Thu Feb 28, 2019 6:15 pm

Hi Paul,

thanks very much for your help!

Ok, the brackets-I see. I inserted them and it works now!
...you can use {Ctrl c} to copy highlighted text to the clipboard...before the {Var15 GetClip} you can highlight text and then click the button.
Actually my last posted code is only a part of my macro. The line is highlighted by a command above which I didn't post. But:
First, I don't know whether I can use an "OR"-function e.g. if I can search for "A1abc" and "B1abc" simultaneously.
By this I want to check at first, if I need a replace-routine at all. Because I would like to avoid rewriting that line if it doesn't need a modification.
Is it possible to write it like that?

{If (Var15=A1* OR B1* OR C1*) [{Goto ReplaceA1B1C1}] Else [{Goto End}]} ?

Cause if that is possible and my search-terms don't match, I could jump to the next actions without needing to insert that unmodified line again by {Var15} which performs quite slowly.
So, is the OR-function possible?

Thanks in advance!
Michael

Wavget
Site Admin
Posts: 91
Joined: Wed Jan 16, 2019 4:32 pm

Re: If and goto

Post by Wavget » Sat Mar 02, 2019 11:34 am

Typeitin currently does not support the OR function in the IF function. I will add this to the list for future versions.

There is a work around using nested IF statements:

{If (Var15!A1*) [{If (Var15!B1*) [{If (Var15!C1*) [{Goto NotFound}]}]}]}
{Dialog 0,Information,[Ok],A1 B1 C1 found}
{Goto End}
{Label NotFound}
{Dialog 0,Information,[Ok],{Var15}{Enter}A1 B1 C1 not found}
{Label End}


The first line is basically "if variable does not contain A1 and does not contain B1 and does not contain C1 then jump over replacement code"

Paul.

BarneyEuropa
Posts: 3
Joined: Tue Feb 26, 2019 4:01 pm

Re: If and goto

Post by BarneyEuropa » Sat Mar 02, 2019 1:02 pm

Hi Paul,
GREAT!
Thanks a lot and:
God bless you, brother!

Post Reply