Beaue Posted January 15, 2013 Report Share Posted January 15, 2013 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. Quote Link to comment Share on other sites More sharing options...
Look_Up Posted January 15, 2013 Report Share Posted January 15, 2013 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 Quote Link to comment Share on other sites More sharing options...
Beaue Posted January 15, 2013 Author Report Share Posted January 15, 2013 Thanks for the suggestion! It sounds like this is what I'm looking for. I'll read up on it in the help file (I love the MacEx help file) and see if this will work for my purposes. Quote Link to comment Share on other sites More sharing options...
Samrae Posted January 15, 2013 Report Share Posted January 15, 2013 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. Quote Link to comment Share on other sites More sharing options...
paul Posted January 16, 2013 Report Share Posted January 16, 2013 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"/> Quote Link to comment Share on other sites More sharing options...
Look_Up Posted January 16, 2013 Report Share Posted January 16, 2013 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 Quote Link to comment Share on other sites More sharing options...
paul Posted January 16, 2013 Report Share Posted January 16, 2013 As has been stated already, Look_Up's response does not provide a solution to the problem because the Switch...Case commands look for equality and do not handle the Contains that was specified in the original question. Quote Link to comment Share on other sites More sharing options...
Rustywinger Posted January 30, 2013 Report Share Posted January 30, 2013 <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. Quote Link to comment Share on other sites More sharing options...
Beaue Posted February 6, 2013 Author Report Share Posted February 6, 2013 Interesting, I've never used the Split String command before. I'll play with it. Quote Link to comment Share on other sites More sharing options...
Cory Posted February 11, 2013 Report Share Posted February 11, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.