Page 1 of 1

Logical NOT when comparing strings

Posted: Sun Oct 16, 2016 9:26 pm
by John R. Sowden
I guess I have been too spoiled in Foxpro 2.6/DOS. I use the not operator in string comparison all the time, e.g.:

while not choice$ $ "ABCDEFQ"
input routing
wend
(use the input data)

This seems to be so basic for a language, that I spent a lot of time searching for the answer, in case different words were used to describe it.

this also uses the logical substring search, but I will put that in another message so it can be addressed separately.

John

Re: Logical NOT when comparing strings

Posted: Sun Oct 16, 2016 9:54 pm
by IdeasVacuum
Hi John

I do not understand your snippet, but you can indeed use Not:

Code: Select all

While Not UCase(choice$) = "ABCDEFQ"
input choice$
Wend
;Don't try this at home

Re: Logical NOT when comparing strings

Posted: Sun Oct 16, 2016 10:24 pm
by John R. Sowden
I'm a little lost. ucase converts lower case to upper case. I want to compare strings. The docs say that the NOT function does not work with strings.

John

Re: Logical NOT when comparing strings

Posted: Sun Oct 16, 2016 10:58 pm
by Demivec
Would something like this work for you?

Code: Select all

Macro NotIn(variable, content = "")
 Bool(Not FindString(content, variable))
EndMacro

OpenConsole()

Print("Select a choice (ABCDEFQ)?") ;prompt
While NotIn(choice$, "ABCDEFQ")
  ;input routing
  choice$ = Input() ;need to press enter after each input for this method
 Print("...") ;simple display to show we are whistling while we wait;)
Wend
;(use the input Data)

Re: Logical NOT when comparing strings

Posted: Mon Oct 17, 2016 5:27 am
by Mistrel
We USED to have this behavior but it was removed in PureBasic 5.0. It was one of my favorite features and I used it everywhere..

http://www.purebasic.fr/english/viewtop ... 13&t=57715

Re: Logical NOT when comparing strings

Posted: Mon Oct 17, 2016 12:04 pm
by IdeasVacuum
Hi John

I introduced UCase so that in the string comparison it would be like-for-like. I'm sorry I did not know that NOT had been removed from string operations - that is a great pity, it seems logical to use it (pun intended).
You can do it like this (tested!):

Code: Select all

OpenConsole() ;To enable use of Input()
     PrintN("Enter a String")

While UCase(choice$) <> "ABCDEFQ"
            choice$ = Input()
Wend
....but do you really want a Console program rather than a nice shiny Window?

Re: Logical NOT when comparing strings

Posted: Mon Oct 17, 2016 1:17 pm
by Dude

Re: Logical NOT when comparing strings

Posted: Tue Oct 18, 2016 7:19 am
by Lord
If you really want to use "NOT", use it like this:

Code: Select all

OpenConsole() ;To enable use of Input()
     PrintN("Enter a String")

While Not Bool(UCase(choice$) = "ABCDEFQ")
            choice$ = Input()
Wend
But as IdeasVacuum already stated it (still) works like this:

Code: Select all

OpenConsole() ;To enable use of Input()
     PrintN("Enter a String")

While Not UCase(choice$) = "ABCDEFQ"
            choice$ = Input()
Wend