Jump to content
Macro Express Forums

Help with the "Case" command


Wolters
 Share

Recommended Posts

Hi,

 

I am trying to understand the case command, and I think that I with this command will be able to execute something like this:

 

case:

 

%T1% contains "sugar"

: do this

 

%T1% contains "pepper"

: do that

 

end case

 

Now I have not found any examples of how to get about with the proper syntax, so I would appreciate if someone could help me pointing out some examples with case and how to do this when you want to check if a string contains this or that and then take appropriate action.

 

Thanks!

Link to comment
Share on other sites

Hi,

 

I am trying to understand the case command, and I think that I with this command will be able to execute something like this:

 

case:

 

%T1% contains "sugar"

: do this

 

%T1% contains "pepper"

: do that

 

end case

 

Now I have not found any examples of how to get about with the proper syntax, so I would appreciate if someone could help me pointing out some examples with case and how to do this when you want to check if a string contains this or that and then take appropriate action.

 

Thanks!

 

The Help in Macro Express 3 and ME Pro is one of the great strengths of these programs. I wish my other applications all reached the same standard. In this particular, er, case, the example given under Switch / Case Commands is simple but if you read it together with the detailed explanation of each command it does clearly show the way to do it. I'll paste it below for convenience:

 

This example tests the value in the T1 variable for the word Found or any of the words Done, Finished or Completed.

 

Switch (T1)

Case: Found

Text Box Display: T1 equals Found

End Case

Case: Done

Case: Finished

Case: Completed

Text Box Display: The comparison is done

End Case

End Switch

 

In summary, that part of the macro examines the variable T1 and if it equals 'Found' it displays an appropriate message. If on the other hand it equals either 'Done', 'Finished' or 'Completed' it displays the altrenative message.

 

So, the equivalent for your example would be:

 

This example tests the value in the T1 variable for the word Sugar or Pepper.

Switch (T1)

Case: Sugar

Text Box Display: T1 equals Sugar

[More sugary commands here]

End Case

Case: Pepper

Text Box Display: T1 equals Pepper

[More peppery commands here]

End Case

End Switch

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Thanks Terry,

 

I did find the Help section on this command, the problem being that being a non-programmer, I do need a bit more in depth explanation... Sorry!

 

So, I take it that the Switch-part determins which variable to examine in the following procedure???

 

What I do not really understand is how this "Case: Sugar" should be expressed?

 

I think I have the general grasp of the intention of the Switch/Case command, but in order to comprehend it all the way, I feel I am missing something!

 

Regards,

 

 

Dag

Link to comment
Share on other sites

Thanks Terry,

 

I did find the Help section on this command, the problem being that being a non-programmer, I do need a bit more in depth explanation... Sorry!

 

So, I take it that the Switch-part determins which variable to examine in the following procedure???

 

What I do not really understand is how this "Case: Sugar" should be expressed?

 

Case: Sugar just means "The case when the variable T1 is the text string 'Sugar'."

 

Try it in a simple macro and you'll see how easy it is. (Although, as John said, not very flexible for more complex logic tests.)

 

--

Terry, East Grinstead, UK

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