Hm, interesting.
[If Not var1 = "texttexttext"] does not throw an error.
[If var1 = Not "texttexttext"] does.
For the sake of expanding my database of knowledge, I ask the following question.
Why?
The second one was a DUH moment for me. *facepalm*
...and as for the first, are you sure that it's copied/been typed correctly? Doesn't throw an error here.
The first case compiles and executes flawlessly on my system*, odd that it doesn't on LFS'.
Interestingly, I just discovered that you can convert a non-boolean comparison into a boolean, like so:
Bool1 = ( Var1 = "texttexttext" )
Pretty nifty.
*Vista Home Premium 32-bit SP2; Phrogram 2.5.3169.17574, non-admin user.
I declared it as a String.
Just be be clear is this what you had?
Program MyNewProgram Method Main() Define var1 As String Define itWorks As Boolean itworks = False If Not var1 = "texttexttest" Then itWorks = True End If If var1 = Not "texttexttext" Then itworks= True End If End MethodEnd Program
On my Phrogram (2.1.2751) the second If statement shows a syntax error on the Not (where I underlined)
The background here is to do with operator precedence when there are no parentheses
Not is an operator that operates on booleans. It takes TRUE/FALSE and flips it the other way.
= is either an assignment or an comparison. A comparison operator takes the 2 operands and returns a boolean.
So the 1st IF statement condition Not var1="texttexttext" is really evaluated like this Not (var1="texttexttext)which works becuase the = operator returns a boolean that Not can work on.
The 2nd IF statement condition var1 = Not "Texttexttext"is evaluated like this var1 = (not "Texttexttext")which makes no sense becuase you can't Not a string.
Since you didn't use parentheses how does the compiler know what to do? This is an age old question.Whats the asnwer to this?4 + 2 * 6 =?Is it 36 becuase (4 +2) * 6 or is it 16 becuase 4 + (2*6)?In most place in the workd its 16 becuase multiplication gets precendecen if parentheses are not there.
Where there is ambiguity the rules for Phrogram are defined such that = gets precendence over Not.
The 1st IF statement could be (Not var1) = "text"or Not (var1 = "text")Since = is more important the 2nd once is chosen.
The 2nd IF statment is not ambiguous. You can only write it as var1 = (Not "text")So it fails.
Long explanation - hope it makes sense.