ffsidfk

If Then statement w/ var's not evaluating as expected...

6 posts in this topic

#1 ·  Posted

This is... odd...

#NoTrayIcon
#include <MsgBoxConstants.au3>
CheckScreenSaver()
func CheckScreenSaver()
   Local $TmpHKCUScrnSvrPath = "C:\Windows\System32\scrnsave.scr"
   Local $OrigHKCUScrnSvrPath = RegRead("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")
   MsgBox($MB_SYSTEMMODAL, "ScrnSave Change", $OrigHKCUScrnSvrPath & @CRLF & $TmpHKCUScrnSvrPath)
   If Not $OrigHKCUScrnSvrPath = $TmpHKCUScrnSvrPath Then
   RegWrite("HKCU\Control Panel\Desktop","SCRNSAVE.EXE", "REG_SZ", "C:\Windows\System32\scrnsave.scr")
   MsgBox($MB_SYSTEMMODAL, "ScrnSave Change", "Path Changed")
   Else
   MsgBox($MB_SYSTEMMODAL, "ScrnSave Change", "Paths are equal")
EndIf
EndFunc     ;==>CheckScreenSaver

$OrigHKCUScrnScrPath is C:\Windows\System32\ssText3d.scr
(This is verified in the first MsgBox)

Yet, the statement is being evaluated as True/Equal/What have you. The regwrite isn't happening and I'm getting the 'Paths are equal' MsgBox.

I've also tried double == ( If Not $OrigHKCUScrnSvrPath == $TmpHKCUScrnSvrPath Then). Same result.

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

You're mixing operators' priority wrong: in If Not XXX = YYY ... Not is evaluated first as in If (Not XXX) = YYY ...

Use parenthesis If Not (XXX = YYY) ... or much simpler If XXX <> YYY ...


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#3 ·  Posted

12 hours ago, jchd said:

You're mixing operators' priority wrong: in If Not XXX = YYY ... Not is evaluated first as in If (Not XXX) = YYY ...

Use parenthesis If Not (XXX = YYY) ... or much simpler If XXX <> YYY ...

Ahh! Thats not the type of logic I'm used to, but that makes sense. It's also not really defined on the help pages as far as I could see. :-(
I checked If and If... Else... EndIf

Is there a special syntax for using the other operators? Suchas:

If $var1 <> "" and $var2 <> "1" Then

Do those need to be wrapped in brackets?

Share this post


Link to post
Share on other sites

#4 ·  Posted

In help, read Language Reference - Operators to find the precedence applied.

After reading the above doc, you'll find that the answer is no ( Do those need to be wrapped in brackets? ).

BTW, about " Thats not the type of logic I'm used to " which logic (meaning programing language) would set NOT priority below anything else?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#5 ·  Posted

Thanks for the pointer to the help section!!
The reason I asked the latter is because

If $var1 <> "" and $var2 <> "1" Then

wasn't evaluating as expected, but

If not ($var1 = "") and $var2 <> "1" Then

does.

I have no idea if any programming language sets NOT priority below anything else.
It seems like that structure has worked for me in the past. That's not to say that its correct, it's just never failed for me.

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

37 minutes ago, ffsidfk said:

The reason I asked the latter is because

If $var1 <> "" and $var2 <> "1" Then

wasn't evaluating as expected, but

If not ($var1 = "") and $var2 <> "1" Then

does.

This is not my experience nor how what AutoIt actually behaves:

Local $a = ["", "1", "2"]

For $var1 In $a
    For $var2 In $a
        ConsoleWrite('$var1 = "' & $var1 & '", $var2 = "' & $var2 & '"' & @TAB & _
                    'conditions are ' & (($var1 <> "" and $var2 <> "1") = (not ($var1 = "") and $var2 <> "1") ? '' : 'not ') & 'equivalent' & @LF)
    Next
Next

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
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