Jump to content

Question About The Operator "Not"


Recommended Posts

Ok, sorry, if this has been asked before.. But take this example for instance:

$var=InputBox("Title","Message","Box","",190,115)
If $var=Not "Text1" Or Not "Text2" Then
    MsgBox(0,"Title","Message")
    Exit
EndIf

In this example, if I use the input box to set $var to something like "Text3," the script, in my opinion, should exit because then $var isn't "Text1" or "Text2." But, it doesn't work like that when I run the script. It'll just accept it. If I change the "Text"s to a number, then it exits as it should. So, my question is that the operator "Not" only works with numerals? If so, how can I make my script work the way I want? Do I change the text into some kind of number sequence?

Link to comment
Share on other sites

$var=InputBox("Title","Message","Box","",190,115)
If Not $var = "Text1" Or Not $var = "Text2" Then
    MsgBox(0,"Title","Message")
    Exit
EndIf

The Not should go before the condition, and it inverts the result of the condition

Regards,Josh

Link to comment
Share on other sites

@JFee, just tried it but it doesn't work.

SideNote: I've tried using <> instead, but it only works like this:

$var=InputBox("Title","Message","Box","",190,115)
If $var<>"Text1" Then
    MsgBox(0,"Title","Message")
    Exit
EndIf

I doesn't work if I put in another expression with "Text2."

Link to comment
Share on other sites

Hey, newbie, this is a great question, to me. I am the philosophically-minded type and Not is an interesting operator in many languages.

Before I get into the philosophy, we'll talk about the code, so I don't upset the mod's by hijacking the thread or anything.

$x = Not True; - returns False

$x = (Not "Sally" = $Bertie); returns False if $Bertie contains a string value "sally" or if it's "Sally" but not " saLLY"

$x = Not 0; - returns True

$x = Not -1; - returns False because -1 evaluates to True when converted to boolean, which the Not operator seems to do.

Now - on with the philosophy -- Okay you know like Obama Hussein Barak, I mean he is so Not there with this Change thing - I mean so many of us are so Not intererested in vague return values of Change of our country - what could it be he is going to Change - the Freedoms we enjoy in the United States? Change the way the war is going and see to that we loose? Change the amount of money and wealth as a percentage of GDP upwards that his government will control - I mean it is so Not what we want; so Not there at all like dude.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Thanks for the help, first of all. Erm, I understand the 1st, 3rd, and 4th examples, but the 2nd line is a bit confusing. The example is saying that $x=false if $Bertie=Sally, sally, saLLY, etc. because the operator "=" is not case-sensitive (that's how I figure, I don't understand how you came up with that if "=" is being used and not "==")? Right now, I have a feeling "Not" won't be able to complete my task at hand. So, do you know a way I could make the script exit if $var doesn't equal one of two specific strings?

Link to comment
Share on other sites

$var=InputBox("Title","Message","Box","",190,115)
If Not $var = "Text1" Or Not $var = "Text2" Then
    MsgBox(0,"Title","Message")
    Exit
EndIf

The Not should go before the condition, and it inverts the result of the condition

Wrong, because NOT operator not compare a strings, his checked 1 or 0, True or False

In below example NOT operator checked a $var, if $var not empty, then $var = True (1), else False (0)

$var = InputBox("Title", "Message", "Box", "", 190, 115)

If Not $var Then MsgBox(0, "Title", "Message") ;condition = True
Link to comment
Share on other sites

So, if I'm reading this correctly (it's almost midnight), "Not" can't be used to compare strings? If so, how can I make a "If...Then" sequence compare an inputed string with either of two specific strings? So far, I can only make the "If...Then" sequence compare the inputed string with only one string.

Link to comment
Share on other sites

So, do you know a way I could make the script exit if $var doesn't equal one of two specific strings?

If (Not $var == $specificStringNo1 And Not $var == $specificStringNo2) Then ExitoÝ÷ ØwöÆ¥-ë-)¶  b²Zæ²«a,^v)ðØb´w«z+æ¬êí¢éÝz»-jwpk&®¶­sdbæ÷Bb33c·f"ÓÒb33c·7V6f57G&ætæóFVà bæ÷Bb33c·f"ÓÒb33c·7V6f57G&ætæó"FVâW@¤VæD`oÝ÷ Ù«¨´Ú-ªê-È+y«[yÆ®±èʧyçm¡ÈZ³­rÞ¥æ­yÙrÊ¢}ý¶wu©e¶¬jëh×6If $var = True Then
    $var = False
Else
    $var = True
EndIfoÝ÷ Û^Øb±Ú²Ø^±©{¶Øb®¶­sbb33c·f"Òæ÷Bb33c·f
Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

@Jon8c: "Not" can be used, but you must be aware of operator precedence and how it affects numbers and strings differently.

See the examples at the end of this post.

@Squirrely1: In order for everyone to understand this better, we need to make a few corrections...

If (Not $var == $specificStringNo1 And Not $var == $specificStringNo2) Then ExitoÝ÷ ØwöÆ¥-ë-)¶  b²Zæ²«a,^v)ðØb·ú®¢×+0Ygz÷«zö¥¹«^¶»Â+a²ÚâyÆ®±ãhµ§ßyËl²ÚâÙî·«±Ø}êÞÙrjwmjG¬¦·yקqê/z¶¥azº)z¶­¢»*.¶·¶+eG«a¦ºé¢¶¥¦Ëh²0Ê«Â䧲ox ­§nj×jëh×6If (Not $var == $specificStringNo1 And Not $var == $specificStringNo2) Then Exit
If (False == $specificStringNo1 And False == $specificStringNo2) Then Exit
If (False And False) Then Exit
If (False) Then Exit ; Won't exit because False is never True.oÝ÷ Ù&¦zènW¦Â+a¶¬yìZ^²«¨µéÚoÝ÷ Ù«¨´Ú-ªê-È+y«[yÆ®±èʧyçm¡ÈZ³­rÞ¥æ­yÙrÊ¢}ý¶wu©e¶¬jëh×6If $var = True Then
    $var = False
Else
    $var = True
EndIfoÝ÷ Û^Øb±Ú²Ø^±©{¶Øb®¶­sbb33c·f"Òæ÷Bb33c·f oÝ÷ Ûú®¢×£ajÜßÛÞæ«çm«jºM¢oÝ÷ Øêâ*.{"²Ú'ºÈ§Ú-jëh×6$var=InputBox("Title","Message","Box","",190,115)
If Not($var="Text1" Or $var="Text2") Then
    MsgBox(0,"Title","Message")
    Exit
EndIf

Hope that helps.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

Wow...I feel stupid now muttley Thanks. I agve up on using "Not" about half way into this thread yesterday, and I tried using "<>" instead. It didn't work for me because I mistakenly used "Or" instead of "And." Thanks again.

Link to comment
Share on other sites

Skruge - you've really given me a heads-up on this issue, and you've inspired me to investigate all about operators, expressions and keywords.

For my reference, this code will never exit the script then ...

If Not $givenString == $specificString Then ExitoÝ÷ Ù©Ýج¶¬jg±«­¢+Ù%ÀÌØíÍÁ¥¥MÑÉ¥¹ôô9½ÐÀÌØí¥Ù¹MÑÉ¥¹Q¡¸á¥ÐoÝ÷ ÚÊ0zÈhºWn±êZ­éí뱩h·^­ëaz·¢±£hµ«­¢+Ù%9½Ð ÀÌØí¥Ù¹MÑÉ¥¹ôôÀÌØíÍÁ¥¥MÑÉ¥¹¤Q¡¸á¥oÝ÷ ØèºwhºÛajÝ7êö«
is bad code because the boolean Keywords False/True should not be used in expressions - and this brings to mind the definition of an expression:

Definition: An "expression" is something that can be stored in a variable, except that booleans should not be used in expressions because they can lead to unpredictable results.

I'm sure this definition needs work, but it is the best I have going so far.

Das Häschen benutzt Radar

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...