Page 1 of 2

PB5.00b7 no longer allows testing Not with string?

Posted: Thu Oct 25, 2012 12:03 pm
by Kukulkan
With the most recent V5.00Beta7 I can no longer test strings using Not?

Code: Select all

If Not Test.s
  ; do something
EndIf
Throws error Line 1: 'Not' operand can not get using with strings.

Why? My code compiled fine with the previous versions up to beta 4. Now it throws errors every here and then...

And the sentence is wrong spelled I think. Better is "...can not get used with..."

Kukulkan

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Thu Oct 25, 2012 12:05 pm
by Fred
That's it. It barely worked only for simple cases (if you were lucky), and the doc explicitely forbid this use, so now the compiler enforce this rule to avoid strange behaviours.

It can be replaced by:

Code: Select all

If String$ = ""

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Thu Oct 25, 2012 12:12 pm
by STARGĂ…TE
Same for:

Code: Select all

If A$ XOr B$

EndIf
now:

Code: Select all

If A$<>"" XOr B$<>""

EndIf

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Thu Oct 25, 2012 12:27 pm
by Kukulkan
Ok, I'll have to change code now...

If this was a source for errors in the past, I agree with this. Seems better style.

Kukulkan

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Thu Oct 25, 2012 6:21 pm
by BorisTheOld
Kukulkan wrote: Throws error Line 1: 'Not' operand can not get using with strings.

And the sentence is wrong spelled I think. Better is "...can not get used with..."
More correctly, the message should read: 'Not' operand cannot be used with strings.

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Sun Oct 28, 2012 9:15 pm
by Psychophanta
IMO, for conditional expressions, the 'Not' is a nonsense, because only 'Or', 'And' and 'XOr' are necessary.

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Fri Nov 02, 2012 11:42 pm
by Crusiatus Black
Psychophanta wrote:IMO, for conditional expressions, the 'Not' is a nonsense, because only 'Or', 'And' and 'XOr' are necessary.
Why is 'Not' a nonsense?

Code: Select all

If (Not (a And getSomething(b) > 20 And isSomething(a)))
Is 'Not' not convenient in these situations?

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Sat Nov 03, 2012 10:38 am
by Psychophanta
I meant it is a surplus word since it can be done in other way in all cases. Even i realize it could be a little bit less readable sometimes.

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Tue Nov 13, 2012 12:03 pm
by Niffo
Fred wrote:That's it. It barely worked only for simple cases (if you were lucky), and the doc explicitely forbid this use, so now the compiler enforce this rule to avoid strange behaviours.
:cry: I will have to rewrite tons of test statements in my projects. It also looks like a regression because near all other programming languages accepts this syntax.

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Tue Nov 13, 2012 3:47 pm
by BorisTheOld
Niffo wrote:It also looks like a regression because near all other programming languages accepts this syntax.
The thing to remember about "IF" statements, in any language, is that they test the value of an integer expression. That's why NOT, XOR, AND, etc, can be used. However, a string is not a valid integer expression and must always be compared to something in order to create an integer value that represents True or False.

For example, the following are valid:

If String1 = String2
If Not (String1 = String2)

But the following are invalid:

If String1
If Not String1

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Tue Nov 13, 2012 3:55 pm
by PMV
One of PB features is, that "If String" is valid. :wink:

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Tue Nov 13, 2012 7:31 pm
by BorisTheOld
I was talking about how the "If" statement works in real languages. :lol:

And yes, PB does allow "If string". Currently, a null string returns false and a non-null string returns true.

Therefore, using "If Not string" would seem to be a valid statement, it's just that it wasn't implemented correctly. However Fred says not, and suggests that we use the more normal forms such as, "If string1 = string2", etc, which is the way other languages work.

I would therefore argue that the "If string" usage should also be disallowed.

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Tue Nov 13, 2012 7:54 pm
by jassing
BorisTheOld wrote:I would therefore argue that the "If string" usage should also be disallowed.
I agree with that -- I had to change a lot of code that I used "if not cValue" for "is cvalue empty" (or "") - if the 'not' variation is invalid, then "if stringvar" should also be invalid.


Moreover, if "If Not cValue" didn't work as you expected it to; we can not count on "If cValue" to work as we expect it to -- correct?

I mean

if not .f. is invalid, how can if .t. be valid?

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Tue Nov 13, 2012 11:27 pm
by PMV
Its always the same ... just because something that was never
allowed to be was just used because it seemed to work fine.
Now it is disallowed and some people are going crazy. The
only think i can see here is, that it should be blocked from
the beginning to avoid this. :lol:


Maybe you have luck and Fred will tell you why it is like it is
... good luck. :)

MFG PMV

Re: PB5.00b7 no longer allows testing Not with string?

Posted: Tue Nov 13, 2012 11:46 pm
by luis
BorisTheOld wrote:
Kukulkan wrote: Throws error Line 1: 'Not' operand can not get using with strings.

And the sentence is wrong spelled I think. Better is "...can not get used with..."
More correctly, the message should read: 'Not' operand cannot be used with strings.
Actually should be "operator" :wink: