1. True/False statements with OBJECT variables
- Posted by ST Qu Man <STQuMan at AOL.COM> Apr 24, 1998
- 488 views
If I do something like object a,b a="abcdefghijklmnopqrstuvwxyz" b=gets(0) If b=a then* puts(1,"YAY! CORRECT!") else puts(1,"BAD!") end if *I get a message at this part of the program and it says (If b != a): sequences arent equal in length (6 (6 chars) != 26 (26 chars)) The same thing happens when I do something like: object a,b a="" while a="" do --when 'a' changes. a=gets(0) b=gets(0) end while How do I fix that???? PLEASE HELP ME. Trivia Program Makers Are Very Ineffective If You Can't Compare String Variables. Thanks, St Qu Man
2. Re: True/False statements with OBJECT variables
- Posted by MAP <ddhinc at ALA.NET> Apr 24, 1998
- 486 views
ST Qu Man wrote: > > If I do something like > > object a,b > a="abcdefghijklmnopqrstuvwxyz" > b=gets(0) > If b=a then* > puts(1,"YAY! CORRECT!") > else > puts(1,"BAD!") > end if > > *I get a message at this part of the program and it says (If b != a): > sequences arent equal in length (6 (6 chars) != 26 (26 chars)) . . . > How do I fix that???? PLEASE HELP ME. > Trivia Program Makers Are Very Ineffective If You Can't Compare String > Variables. > > Thanks, > St Qu Man use this instead: if not compare(a,b) then puts(1,"YAY! CORRECT!") else puts(1,"BAD!") end if compare() returns zero for objects that "are" equal to one another, hence the need for the "not" in the comparison. Hope this helps, Christopher D. Hickman
3. Re: True/False statements with OBJECT variables
- Posted by Irv Mullins <irv at ELLIJAY.COM> Apr 24, 1998
- 461 views
At 04:20 PM 4/24/98 -0500, you wrote: >if not compare(a,b) then > puts(1,"YAY! CORRECT!") >else > puts(1,"BAD!") >end if > >compare() returns zero for objects that "are" equal to one another, >hence the need for the "not" in the comparison. Until you get used to this "backward" stuff, you may find it clearer to write: if compare(a,b) = 0 then -- think 'zero difference' puts(1,"Same!") else.... Irv Spam Haiku:------------------- Silent, former pig One communal awareness Myriad pink bricks -------------------------------------
4. Re: True/False statements with OBJECT variables
- Posted by Daniel Berstein <daber at PAIR.COM> Apr 27, 1998
- 490 views
>use this instead: >if not compare(a,b) then > puts(1,"YAY! CORRECT!") >else > puts(1,"BAD!") >end if > >compare() returns zero for objects that "are" equal to one another, >hence the need for the "not" in the comparison. Also a "trim" function is useful, specially if your are using a gets(0). Example: function RightTrim(sequence s) if length(s) = 0 then return s end if if s[length(s)] <= 32 then if length(s) > 1 then return RightTrim(s[1..length(s)-1]) else return "" end if else return s end if end function function LeftTrim(sequence s) if length(s) = 0 then return s end if if s[1] <= 32 then if length(s) > 1 then return LeftTrim(s[2..length(s)]) else return "" end if else return s end if end function function AllTrim(sequence s) return LeftTrim(RightTrim(s)) end function if not compare(AllTrim(a),AllTrim(b)) then puts(1,"YAY! CORRECT!") else puts(1,"BAD!") end if Regards, Daniel Berstein.