Jump to content
Macro Express Forums

If contains (alpha characters)


jefferson
 Share

Recommended Posts

Is there any way to get ME to scan a text variable looking for any occurence of a number of characters? Im trying to get macro express to return a meaningful error and allow a retry if anything other than a range of numbers, seperated by a hyphen, is typed in. I dont really want to write 50 repeating if statements. "If contains" as far as i can tell will only accept one character at a time, unless youre looking for an entire string.

 

Basically i want the user to be able to enter 1-10 or 2005-5000, but the macro would reject an entry of 1-m or 2-!0 and then prompt the user to re-enter the variable.

Link to comment
Share on other sites

Sure. The other day I posted a sample macro that validates email addresses that does this same thing. You can get it here. Let's call our evaluated string T1. What I did is to create a variable, let's call it T2 and put all the valid characters in there. In this case a-z, 1-0, and a coupe of special characters like the hyphen, period and plus sign. Then I count the number of characters in T1, call it N1, and create a repeat loop that cycles N1 times. In each loop I get one character starting at position N1. Let's call that T3. I then check to see if T2 contains T3. It's very simple and quick. Oh. And if you want to make sure there is exactly one hyphen you can have an IF statement in there that increments a counter N2 and at the very end if N2 doesn't equal 1 then error out.

 

Also you can use a character range sometimes. For instance less than or equal to 9 AND greater than or equal to zero. In some cases I've even used the Variable Set to ASCII Value in order to get an integer I could evaluate. This is handy to ensure it's a printing character where, say, numbers are next to letters and or you want to have a superset that includes adjacent sets in the standard ASCII table.

 

In my email validation macro I break things in to constituent parts for evaluation, this might work for you if you always have a hyphen.

Link to comment
Share on other sites

That worked perfectly, thanks man.

 

I had to modify it a bit for my purposes but i never would have figured it out if not for your help.

 

I also used a modified version of yours to ensure that a valid "range" was entered. Very helpful. Also gave me some more insight as to what you can do with ME.

Link to comment
Share on other sites

Glad to hear it. When I first started scripting with ME there were several perceived limitations but after thinking on it for a while I almost always found a way. For instance many people instantly dismiss ME's scripting language because there's no "GoTo". But that's not a limitation unless you refuse to think the way the scripting language is arranged. So as long as you are familiar with all the teools and think on it a bit, and get some help from folks here, there's almost always a way.

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...
 Share

×
×
  • Create New...