inserting a plus sign into a text string

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
esuohlluf
Junior Coder
Posts: 41
Joined: Thu Mar 23, 2006 5:33 am

inserting a plus sign into a text string

Post by esuohlluf » Fri Mar 24, 2006 9:03 pm

I have this line of code
WriteLn>WriteFilePath,result,Let>X=X+%OffsetX%

the + is seen as concantenate how can I end up writing X=X+67 ?
(67 as ex of a variable number)

no matter what I try i end up with x=x67

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Mar 24, 2006 9:16 pm

Strange - it works for me. I don't see how the + would be seen as a concatinator for two reasons 1) it is NOT a concatinator in MacroScript and 2) you have it in a string in a WriteLn command - there is no variable assignation or processing going on there.

The following script:

Let>OffsetX=67
Let>WriteFilePath=d:\test.txt
WriteLn>WriteFilePath,result,Let>X=X+%OffsetX%

Gives me a file that looks like this:

Let>X=X+67



The issue you are seeing must be caused by something else - not these lines of code.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

esuohlluf
Junior Coder
Posts: 41
Joined: Thu Mar 23, 2006 5:33 am

Post by esuohlluf » Sat Mar 25, 2006 12:21 am

In the help it does say + is used for concanenation
But apparently there is something in the code, I cannot get the if statement If>OffsetX>=0,PosX to go to label PosX, I have tried several variations . I inserted a message box to verify the variable OffsetX is
positive. I have used this type if statement branching to labels elsewhere
in the macro without trouble. I have tried everything I can possibly think of (used % around the variable used{} ect, tried , you name it I tried it)
I appreciate your help


Let>OffsetX=Xstring-StartXat
Let>OffsetY=Ystring-StartYat
Message>OffsetX
Wait>0.3
If>OffsetX>=0,PosX
WriteLn>WriteFilePath,result,Let>X=X%OffsetX%
Goto>DoneWithX
Label>PosX
WriteLn>WriteFilePath,result,Let>X=X+%OffsetX%
Label>DoneWithX
IF>OffsetY>=0,PosY
WriteLn>WriteFilePath,result,Let>Y=Y%OffsetY%
Goto>DoneWithY
Label>PosY
WriteLn>WriteFilePath,result,Let>Y=Y%+OffsetY%
Label>DoneWithY

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Mar 25, 2006 2:05 am

If I read the help correctly "one of the following operators" I don't think you can do ">=" in a simple If>

Try it like:

If>{%OffsetX%=0 OR %OffsetX%>0},PosX

User avatar
JRL
Automation Wizard
Posts: 3503
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sat Mar 25, 2006 5:12 am

Me_again is correct, you can't do >= in a simple If> but you can use it in a complex If>

If>{%OffsetX%>=0},PosX

will work.

I have also seen the + to concatenate in the help for Complex Expressions, String Operators. In fact its the only thing there. But I have yet to find a way to make it work. Nothing you have posted makes a plus sign concatenate text for me.

I have altered the script that you have posted to make it function properly. I've highlighted the changes in red

Let>WriteFilePath=C:\esuohlluf_test.txt
Let>Xstring=33
Let>Ystring=33
Let>StartXat=20
Let>StartYat=20

Let>OffsetX=Xstring-StartXat
Let>OffsetY=Ystring-StartYat
If>{%OffsetX%>=0},PosX
WriteLn>WriteFilePath,result,Let>X=X%OffsetX%
Goto>DoneWithX
Label>PosX
WriteLn>WriteFilePath,result,Let>X=X+%OffsetX%
Label>DoneWithX
IF>{%OffsetY%>=0},PosY
WriteLn>WriteFilePath,result,Let>Y=Y%OffsetY%
Goto>DoneWithY
Label>PosY
WriteLn>WriteFilePath,result,Let>Y=Y+%OffsetY%
Label>DoneWithY

With the values I've supplied for Xstring, Ystring, StartXat and StartYat, Viewing the file C:\esuohlluf_test.txt with notepad, I see:

Let>X=X+13
Let>Y=Y+13

Hope this helps,
Dick

esuohlluf
Junior Coder
Posts: 41
Joined: Thu Mar 23, 2006 5:33 am

Post by esuohlluf » Sat Mar 25, 2006 8:02 am

I found a error in the code...Y%+OffsetY% should be ....Y+%OffsetY%

BUT that still didnt give me a correct result

I began by try to use the { } as suggested and everytime i have done this running the code shows an unknown identifier ,i eliminate the { ]
and the code runs

I appreciate everyones help and hope you can help me solve this

it is becoming one of those things i get stuck on and refuse to give up

esuohlluf
Junior Coder
Posts: 41
Joined: Thu Mar 23, 2006 5:33 am

Post by esuohlluf » Sat Mar 25, 2006 8:40 am

I tried without the = and I have a result that is correct with the exception of the zero .

It looks like I will need to add one more branch to handle a zero case and
then it should work

I thank everyone for the help

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts