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
Logical NOT when comparing strings
-
- User
- Posts: 19
- Joined: Sat May 10, 2014 2:58 am
- Location: San Rafael, CA USA
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Logical NOT when comparing strings
Hi John
I do not understand your snippet, but you can indeed use Not: ;Don't try this at home
I do not understand your snippet, but you can indeed use Not:
Code: Select all
While Not UCase(choice$) = "ABCDEFQ"
input choice$
Wend
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- User
- Posts: 19
- Joined: Sat May 10, 2014 2:58 am
- Location: San Rafael, CA USA
Re: Logical NOT when comparing strings
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
John
Re: Logical NOT when comparing strings
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
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
http://www.purebasic.fr/english/viewtop ... 13&t=57715
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Logical NOT when comparing strings
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!):
....but do you really want a Console program rather than a nice shiny Window?
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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Logical NOT when comparing strings
Workaround with a macro: http://www.purebasic.fr/english/viewtop ... 86#p434686
Re: Logical NOT when comparing strings
If you really want to use "NOT", use it like this:
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 Bool(UCase(choice$) = "ABCDEFQ")
choice$ = Input()
Wend
Code: Select all
OpenConsole() ;To enable use of Input()
PrintN("Enter a String")
While Not UCase(choice$) = "ABCDEFQ"
choice$ = Input()
Wend
