Code Comments
Programming Forum and web based access to our favorite programming groups."Frank Swarbrick" <Frank.Swarbrick@efirstbank.com> wrote in message news:46D7E17F.6F0F.0085.0@efirstbank.com... [snip] > Not sure why you need this, but perhaps FUNCTION MAX could give you what you > want? > > COMPUTE MAX = FUNCTION MAX(A B) Another intereting approach might be: ----- evaluate function ord-max(A B) - function ord-min(A B) when 1 display "A is less than B" when 0 display "A is equal to B" when -1 display "A is greater than B" end-evaluate ----- A and B may be either numeric or alphanumeric, as long as they are the same.
Post Follow-up to this messageIf you didn't need to use the IF statement, I can think of a number of (ridiculously expensive) ways to do it. (I was thinking of these when I wasn 't looking at the original assignment where we knew the items were numeric) - Create a temp file and SORT it - Create an indexed file (and see what entry you get first) - Put them into a table and use SEARCH (I am not even certain this could wor k) And then there is my favorite (that actually meets the original assignment) - use Object Orientation and create a method for comparing two items, e.g. If whatever::"compare" (Field-A Field-B) Numeric Then Display "Field-A > Field-B) ... where the compare method returns zero if the first operand is > than th e second it returns spaces if the 2nd operand is > than the first - it returns high-values if they are equal (so you would need to do a 2nd te st) *** Don't you think THAT would impress the teacher <G> -- Bill Klein wmklein <at> ix.netcom.com "Rick Smith" <ricksmith@mfi.net> wrote in message news:13dggs41m0sc4c@corp.supernews.com... > > "Frank Swarbrick" <Frank.Swarbrick@efirstbank.com> wrote in message > news:46D7E17F.6F0F.0085.0@efirstbank.com... > [snip] > you > > Another intereting approach might be: > ----- > evaluate > function ord-max(A B) - function ord-min(A B) > when 1 > display "A is less than B" > when 0 > display "A is equal to B" > when -1 > display "A is greater than B" > end-evaluate > ----- > > A and B may be either numeric or alphanumeric, as long as > they are the same. > > >
Post Follow-up to this message"Rick Smith" <ricksmith@mfi.net> wrote in message news:13dggs41m0sc4c@corp.supernews.com... > > "Frank Swarbrick" <Frank.Swarbrick@efirstbank.com> wrote in message > news:46D7E17F.6F0F.0085.0@efirstbank.com... > [snip] > you > > Another intereting approach might be: > ----- > evaluate > function ord-max(A B) - function ord-min(A B) > when 1 > display "A is less than B" > when 0 > display "A is equal to B" > when -1 > display "A is greater than B" > end-evaluate > ----- > > A and B may be either numeric or alphanumeric, as long as > they are the same. > A nice solution Rick. Good job. (At least you thought about it ... :-)) Pete -- "I used to write COBOL...now I can do anything."
Post Follow-up to this message"William M. Klein" <wmklein@nospam.netcom.com> wrote in message news:_7ZBi.297833$rk4.155800@fe09.news.easynews.com... > If you didn't need to use the IF statement, I can think of a number of > (ridiculously expensive) ways to do it. (I was thinking of these when I > wasn't looking at the original assignment where we knew the items were > numeric) > Bill, it doesn't matter if the operands are numeric or not. It is the principle of doing "arithemetic" (in the sense that the ALU does "arithmetic") on them, and testing the resulting sign that matters. (Although I really liked Rick's Evaluate approach as well...) It is not for nothing that the the heart of the CPU is an "Arithmetic Logic Unit"... :-) > - Create a temp file and SORT it > - Create an indexed file (and see what entry you get first) > - Put them into a table and use SEARCH (I am not even certain this could > work) > > And then there is my favorite (that actually meets the original > assignment) > > - use Object Orientation and create a method for comparing two items, e.g. > > If whatever::"compare" (Field-A Field-B) Numeric > Then Display "Field-A > Field-B) C# has almost exactly such a method... as a kind of "blanket" for cases where strings need comparison and the usual innate methods are unsuitable :-) (Fortunately, you only need to use it rarely...:-)) > > > ... where the compare method returns zero if the first operand is > than > the second > it returns spaces if the 2nd operand is > than the first > - it returns high-values if they are equal (so you would need to do a 2nd > test) > > *** > > Don't you think THAT would impress the teacher <G> > I think that, in the unlikely event the teacher reads this thread, he/she will run screaming from the room... :-) Pete -- "I used to write COBOL...now I can do anything."
Post Follow-up to this message"Pete Dashwood" <dashwood@removethis.enternet.co.nz> wrote in message news:5jro26F117mpU1@mid.individual.net... > > > "Rick Smith" <ricksmith@mfi.net> wrote in message > news:13dggs41m0sc4c@corp.supernews.com... [snip] > A nice solution Rick. Good job. > > (At least you thought about it ... :-)) I was just using some erudition triggered by the mention of intrinsic functions. <g>
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.