{"id":2130,"date":"2013-10-24T08:46:32","date_gmt":"2013-10-24T08:46:32","guid":{"rendered":"http:\/\/www.mjtnet.com\/blog\/?p=2130"},"modified":"2013-10-24T08:46:32","modified_gmt":"2013-10-24T08:46:32","slug":"making-your-macros-intelligent-with-if-else-and-endif","status":"publish","type":"post","link":"https:\/\/www.mjtnet.com\/blog\/2013\/10\/24\/making-your-macros-intelligent-with-if-else-and-endif\/","title":{"rendered":"Making your macros intelligent with If, Else, and Endif"},"content":{"rendered":"<div><strong>I&#8217;m often asked how to make a macro behave differently based on certain criteria.<\/strong><\/div>\n<p>The power and flexibility of Macro Scheduler makes this an easy task.<\/p>\n<p><strong>There are hundreds of different reasons<\/strong> you might want to do this. \u00a0Maybe it&#8217;s dependent on :<\/p>\n<div>\n<ul>\n<li>The answer to a question.<\/li>\n<li>The success\/failure of an operation.<\/li>\n<li>The contents of a file.<\/li>\n<li>If a file or folder exists.<\/li>\n<li>If a certain mathematical goal is reached (e.g. if&gt;count=100).<\/li>\n<li>If a certain image is visible on the screen.<\/li>\n<li>If the value of a cell in an Excel spreadsheet matches your requirement.<\/li>\n<li>If an email was\/wasn&#8217;t successfully sent.<\/li>\n<li>If a value on a web page matches your criteria.<\/li>\n<li>The day\/date\/time or year<\/li>\n<\/ul>\n<\/div>\n<p>That&#8217;s just a handful of the many hundreds of variables we can check, but <strong>the basic rules of IF, Else, and Endif are always the same<\/strong>.<br \/>\nLet&#8217;s use asking a simple yes\/no question as an example. \u00a0We simply tell the macro something like this:<\/p>\n<blockquote><p><span style=\"font-weight: bold;\">Ask a yes\/no question<\/span><\/p>\n<p><strong>If the answer is yes<br \/>\n<\/strong><strong>Then do this<\/strong><\/p>\n<p><span style=\"font-weight: bold;\">If the answer is no<br \/>\n<\/span><strong>Then do that<\/strong><\/p><\/blockquote>\n<p>It&#8217;s that simple! \u00a0So, how do we put that into simple Macro Scheduler language? \u00a0Here&#8217;s how :<\/p>\n<pre class=\"brush: macroscript\">\/\/ask a yes\/no question\r\nAsk&gt;Do you like brussel sprouts?,question\r\n\r\n\/\/depending on the answer given, the macro will execute *one* of the two lines below, then continue on with the rest of the script\r\nIf&gt;%question%=YES\r\n    MessageModal&gt;I agree, but let's keep it our secret\r\nElse\r\n    MessageModal&gt;Right.  They're ghastly\r\nEndif\r\n\r\n\/\/you can abbreviate messagemodal to mdl\r\nmdl&gt;OK, on with the rest of this script.<\/pre>\n<div>Without all the comments :<\/div>\n<pre class=\"brush: macroscript\">Ask&gt;Do you like brussel sprouts?,question\r\n\r\nIf&gt;%question%=YES\r\n    MessageModal&gt;I agree, but let's keep it our secret\r\nElse\r\n    MessageModal&gt;Right.  They're ghastly\r\nEndif\r\n\r\nmdl&gt;OK, on with the rest of this script.<\/pre>\n<div>So, in short, we are doing this :<\/div>\n<pre class=\"brush: macroscript\">If&gt;your condition is\/isn't met\r\n  \/\/do this\r\n\r\n\/\/or else\r\nElse\r\n  \/\/do that\r\n\r\nEndif<\/pre>\n<div>&#8220;Else&#8221;, is optional. \u00a0If you don&#8217;t need an &#8220;else&#8221;, just leave it out. \u00a0All you need is the If and Endif. \u00a0This is for if we just need to tell a macro to perform a certain action based on your criteria, but not an alternative action if the criteria is not met.<\/div>\n<pre class=\"brush: macroscript\">If&gt;your condition is met\r\n  \/\/This line only executes if the condition is met, otherwise it's ignored\r\nEndif<\/pre>\n<div><strong>Helpfile links for your reference : <\/strong><a href=\"http:\/\/www.mjtnet.com\/manual\/index.html?ask.htm\">Ask<\/a> |\u00a0<a href=\"http:\/\/www.mjtnet.com\/manual\/index.html?if2.htm\">If<\/a> |\u00a0<a href=\"http:\/\/www.mjtnet.com\/manual\/index.html?messagemodal.htm]Messagemodal\">Messagemodal<\/a><\/div>\n<p><strong>Questions? Reply to this thread.<\/strong> Our support team and our community are always happy to help.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m often asked how to make a macro behave differently based on certain criteria. The power and flexibility of Macro Scheduler makes this an easy task. There are hundreds of different reasons you might want to do this. \u00a0Maybe it&#8217;s dependent on : The answer to a question. The success\/failure of an operation. The contents [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/2130"}],"collection":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/comments?post=2130"}],"version-history":[{"count":22,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/2130\/revisions"}],"predecessor-version":[{"id":2152,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/2130\/revisions\/2152"}],"wp:attachment":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/media?parent=2130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/categories?post=2130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/tags?post=2130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}