Devide/calculate a value

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
ZeitenWanderer
Pro Scripter
Posts: 68
Joined: Wed Dec 07, 2005 7:13 am

Devide/calculate a value

Post by ZeitenWanderer » Sat Nov 01, 2014 12:10 pm

This should be simple, but I keep failing to get out a simple math result:

Let>ImageFile=test.jpg
Dialog>ImageSizeDialog
object ImageSizeDialog: TForm
object MSImage1: tMSImage
AutoSize = True
end
end
EndDialog>ImageSizeDialog
SetDialogProperty>ImageSizeDialog,MSImage1,LoadImage,Imagefile
GetDialogProperty>ImageSizeDialog,MSImage1,Width,Xpixels
GetDialogProperty>ImageSizeDialog,MSImage1,Height,Ypixels
Let>x=xpixels/20,48
Let>y=ypixels/20,65
WriteLN>c:\test\x.txt,result,x
WriteLN>c:\test\y.txt,result,y

I had expected to have a result n devided by 20,48 in the x-file, but instead of the result, I receive a text "n/20,48" in the x.txt file (same in the y,txt). So calculations do not work in the WriteLN command? And how would one fix it?

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

Re: Devide/calculate a value

Post by Marcus Tettmar » Sat Nov 01, 2014 4:24 pm

Let>x=xpixels/20.48
Let>y=ypixels/20.65
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

ZeitenWanderer
Pro Scripter
Posts: 68
Joined: Wed Dec 07, 2005 7:13 am

Re: Devide/calculate a value

Post by ZeitenWanderer » Sat Nov 01, 2014 6:39 pm

Thanks -:-)

But why does this one say "can not read string as float"?
The example in the help goes like this:

Let>decimal=34.6
Let>rounded={round(%decimal%)}

My code is:
Let>x=xpixels/20.48
Let>y=ypixels/20.65
Let>rounded={round(%x%)}
Let>rounded={round(%y%)}

I left out the "%" and it complained, it would not find the identifier "x". So what is wrong and just why? :-) :-)

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

Re: Devide/calculate a value

Post by Marcus Tettmar » Mon Nov 03, 2014 4:02 pm

I'm not replicating (assuming I set xpixels and ypixels to something).

What are xpixels and ypixels set to in your case?

Does this lone macro work:

Code: Select all

Let>decimal=34.6
Let>rounded={round(%decimal%)}

Let>xpixels=100
Let>ypixels=150

My code is: 
Let>x=xpixels/20.48
Let>y=ypixels/20.65
Let>rounded={round(%x%)}
Let>rounded={round(%y%)}
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

ZeitenWanderer
Pro Scripter
Posts: 68
Joined: Wed Dec 07, 2005 7:13 am

Re: Devide/calculate a value

Post by ZeitenWanderer » Mon Nov 03, 2014 9:08 pm

It seems this way works:

Let>x=xpixels/20.48
Let>y=ypixels/20.65
SetRoundMode>0
Let>x={Round(%x%)}
Let>y={Round(%y%)}
WriteLN>c:\test\x.txt,result,x
WriteLN>c:\test\y.txt,result,y
WriteLN>c:\test\z.txt,result,1,5

I could not test thoroughly, though. But the first results look promising. Since this has to work within a larger context, it will take some more days, before I have done all the the tests, I (or other users) would want to be done. :-)

ZeitenWanderer
Pro Scripter
Posts: 68
Joined: Wed Dec 07, 2005 7:13 am

Re: Devide/calculate a value

Post by ZeitenWanderer » Thu Nov 13, 2014 7:28 pm

Sorry to return so late - no nothing works.

Even in your example it complains about line 11 and invalid parameters.

I am lost ....

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

Re: Devide/calculate a value

Post by Marcus Tettmar » Mon Nov 17, 2014 4:30 pm

Line 11? My example has 9 lines. Can you clarify which example and which line?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

ZeitenWanderer
Pro Scripter
Posts: 68
Joined: Wed Dec 07, 2005 7:13 am

Re: Devide/calculate a value

Post by ZeitenWanderer » Mon Nov 17, 2014 9:42 pm

This is the complete code, in here it complains about line 21 and 22. Invalid parameters to round.
But shouldn`t it have all?

Code: Select all

Let>ImageFile=test.jpg
Dialog>ImageSizeDialog
object ImageSizeDialog: TForm
object MSImage1: tMSImage
AutoSize = True
end
end
EndDialog>ImageSizeDialog
SetDialogProperty>ImageSizeDialog,MSImage1,LoadImage,Imagefile
GetDialogProperty>ImageSizeDialog,MSImage1,Width,Xpixels
GetDialogProperty>ImageSizeDialog,MSImage1,Height,Ypixels
Let>x=xpixels/20.48
Let>y=ypixels/20.65
Let>decimal=34.6
Let>rounded={round(%decimal%)}
Let>xpixels=100
Let>ypixels=150
SetRoundMode>0
Let>x={Round(%x%)}
Let>y={Round(%y%)}
WriteLN>c:\test\x.txt,result,x
WriteLN>c:\test\y.txt,result,y
WriteLN>c:\test\z.txt,result,1,5

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

Re: Devide/calculate a value

Post by Marcus Tettmar » Mon Nov 17, 2014 10:05 pm

Huh? Line 21 and 22 are these:

WriteLN>c:\test\x.txt,result,x
WriteLN>c:\test\y.txt,result,y

Your code works fine for me.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

ZeitenWanderer
Pro Scripter
Posts: 68
Joined: Wed Dec 07, 2005 7:13 am

Re: Devide/calculate a value

Post by ZeitenWanderer » Tue Nov 18, 2014 8:43 am

That is because I had excluded the text lines on top. So these are the lines it complains about, if I try to run it in the editor, but it works fine, once it is compiled.

Let>x={Round(%x%)}
Let>y={Round(%y%)}

So, problem solved. :-)

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

Re: Devide/calculate a value

Post by Marcus Tettmar » Tue Nov 18, 2014 8:48 am

if I try to run it in the editor, but it works fine, once it is compiled.
Really? Are you sure you are running from the top when you run in the editor. Remember - the editor is a debugger. You may be executing from part way through the script before x and y have been set.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

ZeitenWanderer
Pro Scripter
Posts: 68
Joined: Wed Dec 07, 2005 7:13 am

Re: Devide/calculate a value

Post by ZeitenWanderer » Tue Nov 18, 2014 8:57 am

And that solved it all ... :-)

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

Re: Devide/calculate a value

Post by Marcus Tettmar » Tue Nov 18, 2014 8:58 am

:!:
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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