EmilyLove Posted February 12, 2015 Share Posted February 12, 2015 (edited) So what I want to happen is when I run the script on a nonNTFS file system it should fail to run and state an error message box. Instead, it fails at the comparing at the If then statement. No matter what the output is for DriveGetFileSystem (which is working properly), it always fails to compare it even when the strings are matching. ;ProblemDemoScript Local $DriveLetter = StringLeft(@ScriptDir, 2) ;Get Drive Letter and Store it. MsgBox(0,"Drive Letter",$DriveLetter) ;Echo Drive Letter MsgBox(0,"Drive Letter",DriveGetFileSystem($DriveLetter)) ;Echo File system If not DriveGetFileSystem($DriveLetter) = 'abcd' Then;intentional set wrong to show it failing. Even with not remove it still fails to properly compare. (problem is here) MsgBox(0, "Safety Engaged", 'Not using NTFS FileSystem. Currently using "'&DriveGetFileSystem($DriveLetter)&'"');should be called under normal conditions. Exit Else MsgBox(0,"No Problems","Successful");should never be called since 'abcd' isn't a real file system and not a possible output. EndIf Edited February 13, 2015 by BetaLeaf Link to comment Share on other sites More sharing options...
Developers Solution Jos Posted February 12, 2015 Developers Solution Share Posted February 12, 2015 Use: If not (DriveGetFileSystem($DriveLetter) = 'abcd') Then Jos EmilyLove 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
EmilyLove Posted February 12, 2015 Author Share Posted February 12, 2015 (edited) Use: If not (DriveGetFileSystem($DriveLetter) = 'abcd') Then Jos Thanks you very much for your help. I implemented this and it's working properly. Now I have another question. Why is the () around the actual command necessary? I want to be able to understand it ya know? Edited February 12, 2015 by BetaLeaf Link to comment Share on other sites More sharing options...
mikell Posted February 12, 2015 Share Posted February 12, 2015 It's because of the operators precedence As the NOT has a higher precedence than "=" it occurs before the = operation Link to comment Share on other sites More sharing options...
Developers Jos Posted February 12, 2015 Developers Share Posted February 12, 2015 Thanks you very much for your help. I implemented this and it's working properly. Now I have another question. Why is the () around the actual command necessary? I want to be able to understand it ya know? So translated to what is state: your initial statement does this: If (not DriveGetFileSystem($DriveLetter)) = 'abcd' Then Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
EmilyLove Posted February 12, 2015 Author Share Posted February 12, 2015 It's because of the operators precedence As the NOT has a higher precedence than "=" it occurs before the = operation I'm afraid I still don't understand. Link to comment Share on other sites More sharing options...
EmilyLove Posted February 12, 2015 Author Share Posted February 12, 2015 So translated to what is state: your initial statement does this: If (not DriveGetFileSystem($DriveLetter)) = 'abcd' Then Jos The first one you posted works fine. Should I be using this one instead? Link to comment Share on other sites More sharing options...
Developers Jos Posted February 12, 2015 Developers Share Posted February 12, 2015 The first one you posted works fine. Should I be using this one instead? No because this is what happened with your initial If which wasn't working! It was comparing not DriveGetFileSystem($DriveLetter) to 'abcd' which ofcourse fails. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
EmilyLove Posted February 12, 2015 Author Share Posted February 12, 2015 (edited) No because this is what happened with your initial If which wasn't working! It was comparing not DriveGetFileSystem($DriveLetter) to 'abcd' which ofcourse fails. Jos I still don't get it. Let me rephrase my original question. When should I put () around the entire statement as in your first example? I want to be able to understand this but I have autism. Could you make a few examples of what does and doesn't work and explain why. Maybe that will help me understand it if I can see examples. To me, when I look at If not drivegetfilesystem($driveletter) = 'abcd' shouldn't it just know that I mean If this statement is not this, then do this? I really want to be able to understand this. I don't like asking for help and perfer to be self reliant. Edited February 12, 2015 by BetaLeaf Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 13, 2015 Moderators Share Posted February 13, 2015 BetaLeaf,AutoIt, like all programming languages, has an "operator precedence" list - for AutoIt this is set out in the Help file: When more than one operator is used in an expression the order in which things happen is controlled by operator precedence. The precedence used in AutoIt is given below. Where two operators have the same precedence the expression is evaluated left to right.From highest precedence to lowest:Not^* /+ -&< > <= >= = <> ==And OrSo let us run through what happened in your comparison:; Original not DriveGetFileSystem($DriveLetter) = 'abcd' ; DriveGetFileSystem always returns a value (either string or numeric) ; NOT is a Boolean operator and AutoIt interprets a value as TRUE, an empty string (") or 0 as FALSE ; So this line reads to AutoIt as not (TRUE) = "abcd" ; Highest operator is "NOT" and the line becomes FALSE = "abcd" ; Which is obviously not what you wanted to happenHappy so far?Now let us force operator precedence by adding parentheses which AutoIt actions before external operators; Original not (DriveGetFileSystem($DriveLetter) = 'abcd') ; AutoIt actions the code inside the parentheses first and so we get (assuming the comparison is TRUE) not (TRUE) ; Which is what you wanted to happenAll clear? M23 EmilyLove 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
EmilyLove Posted February 13, 2015 Author Share Posted February 13, 2015 BetaLeaf, AutoIt, like all programming languages, has an "operator precedence" list - for AutoIt this is set out in the Help file: When more than one operator is used in an expression the order in which things happen is controlled by operator precedence. The precedence used in AutoIt is given below. Where two operators have the same precedence the expression is evaluated left to right. From highest precedence to lowest: Not ^ * / + - & < > <= >= = <> == And Or So let us run through what happened in your comparison:; Original not DriveGetFileSystem($DriveLetter) = 'abcd' ; DriveGetFileSystem always returns a value (either string or numeric) ; NOT is a Boolean operator and AutoIt interprets a value as TRUE, an empty string (") or 0 as FALSE ; So this line reads to AutoIt as not (TRUE) = "abcd" ; Highest operator is "NOT" and the line becomes FALSE = "abcd" ; Which is obviously not what you wanted to happen Happy so far? Now let us force operator precedence by adding parentheses which AutoIt actions before external operators; Original not (DriveGetFileSystem($DriveLetter) = 'abcd') ; AutoIt actions the code inside the parentheses first and so we get (assuming the comparison is TRUE) not (TRUE) ; Which is what you wanted to happen All clear? M23 Yes, This explained it for me. Thank you for taking the time to explain it. I sincerely appreciate it. Have a great day. /Close_thread Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now