jasonwood Posted November 14, 2002 Share Posted November 14, 2002 I've noticed that a lot of users in this forum make frequent use of the "Case" where I probably would have used "If" Could someone exlain the difference, and why one might be prefered over the other? Thanks! -- Jason Wood HeyWoody.com Link to comment Share on other sites More sharing options...
kenneth2k1 Posted November 14, 2002 Share Posted November 14, 2002 Hi: It might help to think of If like a logic statement. "If [ this, then that. Else this]." As you can see, If will only give you one of two results based on if the statement is true or not. Case, on the other hand, will evaluate the entire statement and will give results on the first value that is true, not just one result or the other. I hope that makes sense. Ken Link to comment Share on other sites More sharing options...
jasonwood Posted November 14, 2002 Author Share Posted November 14, 2002 I understand "If" fully from my QBasic days... maybe you could give me a syntax example for Case (I still don't quite get how it works). -- Jason Wood HeyWoody.com Link to comment Share on other sites More sharing options...
kenneth2k1 Posted November 14, 2002 Share Posted November 14, 2002 Ok, let me try this. A typical case statement might look like this: Case (test1, result1, test2, result2, test3, result3, default result) If test1 qualifies, then you will get result1. If test2 qualifies, then you will get result2, and so on. If none qualify, you will get the default result. For example, suppose I have a field (we'll call it Num) that will be populated with numbers 1 through 4. I want a calc field (call it NumCalc) that will change the number to be spelled out ( "1" would be "one"). Sorry its a silly example, but bear with me. I would set up the NumCalc field like this: Case (PatternCount(Num, "1"), "one" , PatternCount(Num, "2"), "two", PatternCount(Num, "3"), "three", PatternCount(Num, "4"), "four", "five"). Just think of it as an If statement with more than one test. Does that help?? Ken Link to comment Share on other sites More sharing options...
jasonwood Posted November 14, 2002 Author Share Posted November 14, 2002 I had to lookup PatternCount() but now it all makes sense! I had been using nested If statements to achieve these results, so I sure am glad I asked! -- Jason Wood HeyWoody.com Link to comment Share on other sites More sharing options...
BobWeaver Posted November 15, 2002 Share Posted November 15, 2002 That is the main reason for using Case statements. Nested If's can be horrible to debug. Apparently Case statements execute faster too. Link to comment Share on other sites More sharing options...
Recommended Posts
This topic is 7968 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now