Wolters Posted March 28, 2010 Report Share Posted March 28, 2010 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! Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 28, 2010 Report Share Posted March 28, 2010 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 Quote Link to comment Share on other sites More sharing options...
Wolters Posted March 28, 2010 Author Report Share Posted March 28, 2010 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 Quote Link to comment Share on other sites More sharing options...
Yehnfikm8Gq Posted March 28, 2010 Report Share Posted March 28, 2010 I was quite disappointed when I looked at the Case command. I was trying to clean up multiple If statements. I found that there are many more possibilities with If (Equals, Contains, Greater Than, Exists etc) and Case is so limited to exact comparison. Quote Link to comment Share on other sites More sharing options...
Wolters Posted March 28, 2010 Author Report Share Posted March 28, 2010 OK, so for the moment I will stick with if-statements even if I feel that it might be resolved much more efficiently with the Case command as I understand the intention of the concept. Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 28, 2010 Report Share Posted March 28, 2010 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 Quote Link to comment Share on other sites More sharing options...
Wolters Posted March 28, 2010 Author Report Share Posted March 28, 2010 Thanks a lot! That really helped! I now understand that I first have to extract and put in to a specific variable what I want to test and THEN perform the Case controll logic! 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.