Complex Expression "Copy" Fails on Leading Zero

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

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

Complex Expression "Copy" Fails on Leading Zero

Post by JRL » Fri Dec 06, 2013 8:39 pm

I think I just found an issue with the complex expression "copy" function. It seems to fail in an If> statement if the parameter has a leading zero. It appears to set variables correctly using Let>. So I was very confused for the last hour. Well... I'm still confused but finally decided there is a problem with the "copy" function.

Using MS version 14.0.17 on WinXP SP3


This works for me

Code: Select all

Let>Invoice_Date=12/17/2013

Let>dd=17
Let>mm=12
Let>ccyy=2013


Let>yr={copy(%Invoice_Date%,7,4)}
Let>mon={copy(%Invoice_Date%,1,2)}
Let>Dy={copy(%Invoice_Date%,4,2)}

If>{((copy(%Invoice_Date%,7,4))=%ccyy%)and((copy(%Invoice_Date%,4,2))=%dd%)and((copy(%Invoice_Date%,1,2))=%mm%)}
  MDL>Invoice is for today
EndIf
This fails for me

Code: Select all

Let>Invoice_Date=12/06/2013

Let>dd=06
Let>mm=12
Let>ccyy=2013


Let>yr={copy(%Invoice_Date%,7,4)}
Let>mon={copy(%Invoice_Date%,1,2)}
Let>Dy={copy(%Invoice_Date%,4,2)}

If>{((copy(%Invoice_Date%,7,4))=%ccyy%)and((copy(%Invoice_Date%,4,2))=%dd%)and((copy(%Invoice_Date%,1,2))=%mm%)}
  MDL>Invoice is for today
EndIf
The only difference in the scripts is changing the day in two variables from "17" to "06".

Guess I''l go back to using MidStr>

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

Post by Marcus Tettmar » Mon Dec 09, 2013 10:45 am

Copy returns a string. And unlike regular Macro Scheduler variables complex expressions care about the difference between strings and numbers.

Your complex If is essentially trying to compare "06" to 06 in other words it is trying to equate the string "06" with the number 6.

The "fix" is to quote the values you're comparing the results of the Copy operations with:

Code: Select all

Let>Invoice_Date=12/06/2013

Let>dd=06
Let>mm=12
Let>ccyy=2013


Let>yr={copy(%Invoice_Date%,7,4)}
Let>mon={copy(%Invoice_Date%,1,2)}
Let>Dy={copy(%Invoice_Date%,4,2)}

If>{((copy(%Invoice_Date%,7,4))="%ccyy%")and((copy(%Invoice_Date%,4,2))="%dd%")and((copy(%Invoice_Date%,1,2))="%mm%")}
  MDL>Invoice is for today
EndIf
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by JRL » Mon Dec 09, 2013 1:57 pm

Thank you. Excellent information. Adding the quotes fixed my problem.

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