Jump to content
Macro Express Forums

Is there a way to shorten logic statements


Recommended Posts

Hi All,

 

I wasn't sure what to search for to see if this topic has already been covered somewhere, and I looked through the MacEx help file.

Is there a way to shorten excessively long logic statements, for example, if my logic statement is as follows:

 

If Variable %T[1]% Containts "1"

OR

If Variable %T[1]% Containts "2"

OR

If Variable %T[1]% Containts "3"

OR

If Variable %T[1]% Containts "4"

OR

If Variable %T[1]% Containts "5"

OR

If Variable %T[1]% Containts "6"

OR

If Variable %T[1]% Containts "7"

OR

If Variable %T[1]% Containts "8"

OR

If Variable %T[1]% Containts "9"

 

Is there a way to shorten this to say something like:

 

If Variable %T[1]% Containts "1-9"

or:

If Variable %T[1]% Containts "1,2,3,4,5,6,7,8,9"

 

I know %T[1]% isn't a good variable name, I'm just using it as an example to illustrate my question.

Basically I want to know if I can search for multiple characters individually in a string, rather than collectively, with one logic statement. Are there any modifiers in MacEx that allow this? As it is now, if I used the above, it would search for "1-9" and "1,2,3,4,5,6,7,8,9" rather than 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9.

Link to comment
Share on other sites

Hello.

You can do this with switch case-command !

 

code example:

<SWITCH Variable="%N[1]%"/>
<CASE Value="1" _COMMENT="in case %N[1]% value is 1"/>
<COMMENT Value="commands, what should I do"/>
<END CASE/>
<CASE Value="2" _COMMENT="in case %N[1]% value is 2"/>
<COMMENT Value="commands, what should I do"/>
<END CASE/>
<COMMENT Value="in case %N[1]% is 3, 4 or 5"/>
<CASE Value="3"/>
<CASE Value="4"/>
<CASE Value="5"/>
<END CASE/>
<END SWITCH/>

 

You are welcome for further question

Link to comment
Share on other sites

The Case statement looks for equality. Beau's example looks to see if the variable contains a number. If %T[1]% contains 4, for example, both Beau's sample and the case statement will work. However if %T[1]% contains 149 the Beau's example will find the 4 but the Case statement will not.

Link to comment
Share on other sites

You'll need to use the External Script command to achieve your goal.

Here's a solution using AutoIt. It displays 0 if no characters between 1 and 9 are found, otherwise it displays 1.

 

Variable Set String %tString% to "1qwertyu4"
External Script: AutoIt
Text Box Display:

 

 

<VARIABLE SET STRING Option="\x00" Destination="%tString%" Value="1qwertyu4" NoEmbeddedVars="FALSE"/>
<EXTERNAL SCRIPT Language="AutoIt" Dest="%tOutput%" Script="ConsoleWrite(StringRegExp($CmdLine[1], \"[123456789]\"))" Parameters="%tString%" Encoding="0"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang3081{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 %tString%\r\n\\par %tOutput%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="2" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
Link to comment
Share on other sites

Use "default case" when no argument match !

 

code example:

<SWITCH Variable="%N[1]%"/>
<CASE Value="1" _COMMENT="in case %N[1]% value is 1"/>
<COMMENT Value="commands, what should I do"/>
<END CASE/>
<CASE Value="2" _COMMENT="in case %N[1]% value is 2"/>
<COMMENT Value="commands, what should I do"/>
<END CASE/>
<COMMENT Value="in case %N[1]% is 3, 4 or 5"/>
<CASE Value="3"/>
<CASE Value="4"/>
<CASE Value="5"/>
<END CASE/>
<DEFAULT CASE _COMMENT="in case no value match above, default case will executed"/>
<COMMENT Value="inside commands here"/>
<END CASE/>
<END SWITCH/>

Thanks to the moderator of this forum, who deleted my post completely.

 

Do you need further information simply, write here what you want to do with the macro.

 

 

Look_Up

Link to comment
Share on other sites

  • 2 weeks later...

<VARIABLE SET STRING Option="\x00" Destination="%MyGoal%" Value="4"/>

<VARIABLE SET STRING Option="\x01" Destination="%MyGoal%" Mask="FALSE" OnTop="FALSE" Left="Center" Top="Center" Monitor="0"/>

<VARIABLE SET STRING Option="\x00" Destination="Target" Value="1,2,3,4,5,6,7,8"/>

<SPLIT STRING Source="%Target%" SplitChar="," Dest="%TVar%" Index="1"/>

<GET ARRAY LENGTH Array="%TVar%" Dest="%TVarL%"/>

<REPEAT START Start="1" Step="1" Count="%TVarL%" Save="TRUE" Variable="%CNT%"/>

<IF VARIABLE Variable="%TVar[%CNT%]%" Condition="\x00" Value="%MyGoal%" IgnoreCase="FALSE"/>

<VARIABLE SET BOOL Destination="%MyGoalReached%" Command="263" Value="TRUE"/>

<END IF/>

<END REPEAT/>

<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 My Goal Reached = %MyGoalReached%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>




The above is fairly self explanatory when put into Macro Express, hope this helps! It requires you create an array of your searchable data, but that is easy enough to do.
Link to comment
Share on other sites

I'm not sure of your ultimate goal but when it comes to any string evaluation in the larger programming world most use a technology called Regular Expressions or RegEx for short and almost every programming language incorporates it. I use it a large amount in my web scrapers and other programming applications. Once before I learned it I wrote a lengthy routine to identify and extract a SSN from a text variable. In RegEx it's a couple of lines and the expression is simply "\d{3}-\d{2}-\d{4}". And it runs instantly as RegEx engines are hyper efficient. I keep thinking that one day I'm going to write a .NET extension app for MEP that will give users some rudimentary RegEx capabilities but I've just been too busy. But if you ever need any help with something like this feel free to contact me.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...