Page 1 of 2

Case Statment

Posted: Tue Nov 04, 2003 11:18 am
by JDionne
I have the following code

Code: Select all

Begin Case
* (PACIFIC TRADE GENERAL):
Case 	Arg1 = '588' Or Arg1 ='570' Or Arg1 ='580' Or Arg1 ='582' Or Arg1 ='583' Or Arg1 ='560' Or Arg1 ='559' Or Arg1 ='549' Or Arg1 ='565' Or Arg1 ='557' Or Arg1 ='552' Or Arg1 ='538' Or Arg1 ='555' Or Arg1 ='579' Or Arg1 ='566' Or Arg1 ='546' Or Arg1 ='574' Or Arg1 ='561' Or Arg1 ='684' Or Arg1 ='553' AND Arg2 >< 'MARSHAL ISL' or Arg2 ><'KWAJALEIN' 
	Ans = 'PACIFIC TOTAL'
End Case

The problem is that once I added the and clause testing the second variable every test came back positive for Pacific Total.
Why did that and statment screw up the case statment?
Jim

Posted: Tue Nov 04, 2003 11:29 am
by chulett
I think you need some parenthesis. :D

Posted: Tue Nov 04, 2003 11:58 am
by Peytot
Begin Case
* (PACIFIC TRADE GENERAL):
Case (Arg1 = '588' Or Arg1 ='570' Or Arg1 ='580' Or Arg1 ='582' Or Arg1 ='583' Or Arg1 ='560' Or Arg1 ='559' Or Arg1 ='549' Or Arg1 ='565' Or Arg1 ='557' Or Arg1 ='552' Or Arg1 ='538' Or Arg1 ='555' Or Arg1 ='579' Or Arg1 ='566' Or Arg1 ='546' Or Arg1 ='574' Or Arg1 ='561' Or Arg1 ='684' Or Arg1 ='553') AND (Arg2 >< 'MARSHAL ISL' or Arg2 ><'KWAJALEIN')
Ans = 'PACIFIC TOTAL'
End Case

That can be better ...

Pey

Posted: Tue Nov 04, 2003 12:06 pm
by JDionne
Peytot wrote:Begin Case
* (PACIFIC TRADE GENERAL):
Case (Arg1 = '588' Or Arg1 ='570' Or Arg1 ='580' Or Arg1 ='582' Or Arg1 ='583' Or Arg1 ='560' Or Arg1 ='559' Or Arg1 ='549' Or Arg1 ='565' Or Arg1 ='557' Or Arg1 ='552' Or Arg1 ='538' Or Arg1 ='555' Or Arg1 ='579' Or Arg1 ='566' Or Arg1 ='546' Or Arg1 ='574' Or Arg1 ='561' Or Arg1 ='684' Or Arg1 ='553') AND (Arg2 >< 'MARSHAL ISL' or Arg2 ><'KWAJALEIN')
Ans = 'PACIFIC TOTAL'
End Case

That can be better ...

Pey
Hmm that gave me a diff respose but now what I needed. It still labled the test case that had both arguments filled in as pacific total even though the second argument = Marshal ISL which should have made the statment not true. Is it because im not giving it something to be if its not true?
Also how do i get the text to wrap around in my window. Right now its all on one long line and i cant realy work with it that way.
Jim

Posted: Tue Nov 04, 2003 12:33 pm
by kcbland
Still working on this???

Cut yourself some slack and write an INLIST function (I grabbed this from a post I did a few days ago)

The new DS Manager function logic would be something like:

Code: Select all

FindValue = Arg1 
ListOfValues = Arg2 
CONVERT "," TO @AM IN ListOfValues 
LOCATE FindValue IN ListOfValues SETTING POSITION Then
   Found = @TRUE
End Else
   Found = @FALSE
End
Ans = Found 

Usage would be something like:

Code: Select all

DEFFUN INLIST(FindValue, ListOfValues) Calling "DSU.INLIST"

Begin Case 
* (PACIFIC TRADE GENERAL): 
Case ( INLIST(Arg1 , '588,570,580,582,583,560,559,549,565,557,552,538,555,579,566,546,574,561,684,553') AND ( Arg2 >< 'MARSHAL ISL' or Arg2 ><'KWAJALEIN' ) 
Ans = 'PACIFIC TOTAL' 
End Case 

Posted: Tue Nov 04, 2003 12:43 pm
by JDionne
What is this bit of code?

Calling "DSU.INLIST"

Is that a built in fucntion of ds 7x?
I get the error

Code: Select all

 
Program "DSU.casetest": Line 27, Unable to open the operating system file "DSU_BP.O/DSU.INLIST".
[ENOENT] No such file or directory
Program "DSU.casetest": Line 27, Unable to load file "DSU.INLIST".
Program "DSU.casetest": Line 27, Unable to load subroutine.
when I try to test the code u posted
Jim

Posted: Tue Nov 04, 2003 12:53 pm
by kcbland
Jim, BASIC has no inherent INLIST function, so I wrote one for you. Create a new FUNCTION in DS Manager just as I describe in the top portion of my most recent post. Then, compile it and test it. Enhance it all you like, putting in TRIMs, UPCASES, whatever.

Posted: Tue Nov 04, 2003 12:54 pm
by kcbland
You'll notice I put a DEFFUN in the case statement logic. When you want to call another user written function from inside another, you will have to do this declaration at the top of any functions needing to "see" the other function. You're missing this in your casetest function, and I suspect you didn't do the INLIST function first.

Posted: Tue Nov 04, 2003 1:00 pm
by JDionne
kcbland wrote:Jim, BASIC has no inherent INLIST function, so I wrote one for you. Create a new FUNCTION in DS Manager just as I describe in the top portion of my most recent post. Then, compile it and test it. Enhance it all you like, putting in TRIMs, UPCASES, whatever.
I have done what you said and I am getting the same result as I got from my code. The statment should be proving false and yet it is treating it like it is true. I dont understand basic right now so I prefer to do it the "Hard Way" because thats all I know and because u have to start at the bottom with anything in life. As it stands both ways are incorrect. It has to do with the way it is handeling the And arg2 >< step. When I test i fill in the arg2 as one of the two in the list that the variable can not be. this test as true though it should not. Any thoughts on that?
Jim

Posted: Tue Nov 04, 2003 1:05 pm
by kcbland
First things first, do you like the INLIST function better? And do you see how you can write FUNCTIONS to make life easier (what I call the Bag of Tricks).

Okay, how about you paste two test cases, one that should prove TRUE and the other FALSE. We can workout your logic from there. I formed your logic into the INLIST function to make life easier and more readable.

Posted: Tue Nov 04, 2003 1:09 pm
by kcbland
Uggh, it hit me. Your "OR" statement should be an "AND" in the second clause.

Your logic should be like:

Code: Select all

INLIST(Arg1,'588,570,580,582,583,560,559,549,565,557,552,538,555,579,566,546,574,561,684,553')
AND NOT(INLIST(Arg2,'MARSHAL ISL,KWAJALEIN' ))
 
Much prettier too? Style points count :)

Posted: Tue Nov 04, 2003 1:12 pm
by JDionne
kcbland wrote:First things first, do you like the INLIST function better? And do you see how you can write FUNCTIONS to make life easier (what I call the Bag of Tricks).

Okay, how about you paste two test cases, one that should prove TRUE and the other FALSE. We can workout your logic from there. I formed your logic into the INLIST function to make life easier and more readable.
I like the inlist funuction...but I dont understand it. I will not use something that I dont understand in a production job. I just cant do that.
as for the test cases:

arg1 arg2
583 MARSHAL ISL
570 Test

The fist example should not be true because MARSHAL ISL is specificaly stated as to not be equal to for the statment to be true and the second should be true because it is not in the list of places that must be not equal to.
Jim

Posted: Tue Nov 04, 2003 1:40 pm
by trobinson
Arg1 = 583 TRUE
Arg2 is not MARSHAL ISL

OR

Arg2 is not KWAJALEIN

Your code as written appears to be true to me in both cases you've presented. MARSHALISL is not KWAJALEIN AND 583 is one of the Arg1 choices. Likewise for Test. Test is not MARSHALISL and Test is not KWAJALEIN so they are both true AND 570 is in the Arg1 list so that is true. TRUE AND TRUE = TRUE

Mixing ANDs, ORS and negative logic! Your case statment should not pass your understanding before putting in production comment.

Posted: Tue Nov 04, 2003 1:48 pm
by kcbland
Here's your logic corrected:

Begin Case
* (PACIFIC TRADE GENERAL):
Case ( Arg1 = '588' Or Arg1 ='570' Or Arg1 ='580' Or Arg1 ='582' Or Arg1 ='583' Or Arg1 ='560' Or Arg1 ='559' Or Arg1 ='549' Or Arg1 ='565' Or Arg1 ='557' Or Arg1 ='552' Or Arg1 ='538' Or Arg1 ='555' Or Arg1 ='579' Or Arg1 ='566' Or Arg1 ='546' Or Arg1 ='574' Or Arg1 ='561' Or Arg1 ='684' Or Arg1 ='553') AND NOT(Arg2 = 'MARSHAL ISL' OR Arg2 = 'KWAJALEIN')
Ans = 'PACIFIC TOTAL'
End Case

Posted: Tue Nov 04, 2003 1:48 pm
by JDionne
trobinson wrote:Arg1 = 583 TRUE
Arg2 is not MARSHAL ISL

OR

Arg2 is not KWAJALEIN

Your code as written appears to be true to me in both cases you've presented. MARSHALISL is not KWAJALEIN AND 583 is one of the Arg1 choices. Likewise for Test. Test is not MARSHALISL and Test is not KWAJALEIN so they are both true AND 570 is in the Arg1 list so that is true. TRUE AND TRUE = TRUE

Mixing ANDs, ORS and negative logic! Your case statment should not pass your understanding before putting in production comment.


Look at the Parentheses the and statement is wrapped in. That makes the statement say or not equal to MARSHALISL or not equal to KWAJALEIN.

The statement as written (at least in all the other languages that I have coded in) would translate into English as...
arg1 equals 5.. or 5.. or 5.. and arg2 not equal to bla bla or not equal to bla bla. I have coded it as simply as I could to keep the logic as clear as I could.
Regards