Jump to content
Macro Express Forums

Wildcards in Case statements


Recommended Posts

I'm trying to put together a series of Case statements but I want them to emulate "Contains". To do that I have to use wildcards with the Case string. By the looks of all the wildcard questions from Search, the most likely answer is that they cannot be used. Confirmation? If that's the case(!!), it's a shame that "Contains" is not an option in the Switch command.

Link to comment
Share on other sites

Yes, you are correct. Case statements do not have a 'wildcard' or 'contains' option.

 

Because of their simplicity, Case statements may result in more concise macros than If statements. However, everything Case statements can do can also be accomplished using If statements. And If statements have a 'contains' option.

Link to comment
Share on other sites

I'm trying to put together a series of Case statements but I want them to emulate "Contains". To do that I have to use wildcards with the Case string. By the looks of all the wildcard questions from Search, the most likely answer is that they cannot be used. Confirmation? If that's the case(!!), it's a shame that "Contains" is not an option in the Switch command.

If your search strings are always at the beginning, then you could do a Case statement on the first n characters, followed by If statements within each Case statement.

Link to comment
Share on other sites

......Because of their simplicity, Case statements may result in more concise macros than If statements. However, everything Case statements can do can also be accomplished using If statements. And If statements have a 'contains' option.

 

Unfortunately my current exercise is to replace If statements where possible and to use Case more in the future.

Link to comment
Share on other sites

Unfortunately my current exercise is to replace If statements where possible and to use Case more in the future.

Well, another idea pops to mind. Why not pass the string you're searching on plus all the possible sequences you would have put in your Case statements to AutoIt for evaluation, use StringInString to evaluate, and return the relevant number. For example, instead of:

select case Searchstring
case "fox"
case "rabbit"
case "wolf"
case else

have AutoIt return 1 for fox, 2 for rabbit, 3 for wolf, 4 for all other cases, then build your MEP Case statement accordingly.

Link to comment
Share on other sites

Well, another idea pops to mind.......have AutoIt return 1 for fox, 2 for rabbit, 3 for wolf, 4 for all other cases, then build your MEP Case statement accordingly.

 

Sorry for my late response. The idea is to simplify macros with numerous Ifs. Going off to AutoIt doesn't fit the bill although it's a neat solution. There's no reason why Case can't have the same options as If (as if it can't!), but I suppose it operates per other applications. It's much clearer seeing a list of alternative returns than a bunch of nested Ifs.

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