scwoobles Posted August 17, 2016 Share Posted August 17, 2016 I am trying to put some better logging into my script that i have been working on but I am having a issue I know its how my if statement is formed but i don't know how to fix it. #requireadmin $blah = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\HideFileExt", "type") if not $blah = "checlls" Then Local $longdate = " Long date set incorrectly ;( " Else Local $longdate = " Long date set Correctly :) " MsgBox(64,"Terminal User Setup", $longdate,0,0) EndIf MsgBox(64,"Terminal User Setup", $blah,0,0) exit Thanks for the help Link to comment Share on other sites More sharing options...
water Posted August 17, 2016 Share Posted August 17, 2016 And the issue is? Can you please provide more information? An error message ... My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
scwoobles Posted August 17, 2016 Author Share Posted August 17, 2016 the value of the registry key is Checkbox, so when I run this is should popup a msgbox saying "Long date set incorrectly ;(", but it gives the opposite, A msgbox that says "Long date set incorrectly :)". so it isn't checking of the value of the reg key is = "Checlls" Link to comment Share on other sites More sharing options...
AutoBert Posted August 17, 2016 Share Posted August 17, 2016 Why not this way? #requireadmin $blah = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\HideFileExt", "type") Local $longdate if $blah = "checlls" Then $longdate = " Long date set Correctly :) " Else $longdate = " Long date set incorrectly ;( " EndIf MsgBox(64,"Terminal User Setup", $longdate,0,0) ;MsgBox(64,"Terminal User Setup", $blah,0,0) exit Link to comment Share on other sites More sharing options...
pluto41 Posted August 17, 2016 Share Posted August 17, 2016 #RequireAdmin Local $longdate, $blah $blah = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\HideFileExt", "type") If not $blah = "checlls" Then $longdate = " Long date set incorrectly ;( " Else $longdate = " Long date set Correctly :) " EndIf MsgBox( 64, "$longdate value", $longdate) MsgBox(64, "$blah value", $blah) Exit Something like this to begin with? Like Declare variables and MsgBoxes outside the If statement. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 17, 2016 Developers Share Posted August 17, 2016 Just put brackets around a test when putting not in front of it! If not ($blah = "checlls") Then Else the test is read as If (not $blah) = "checlls" 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...
scwoobles Posted August 17, 2016 Author Share Posted August 17, 2016 Thank you AutoBert, Pluto41, Jos. the only one that worked out of those sugesstions was autobert's. Thanks again Link to comment Share on other sites More sharing options...
AutoBert Posted August 17, 2016 Share Posted August 17, 2016 The suggestion from @Jos is working too: #requireadmin $blah = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\HideFileExt", "type") Local $longdate if Not ($blah = "checlls") Then $longdate = " Long date set incorrectly ;( " Else $longdate = " Long date set Correctly :) " EndIf MsgBox(64,"Terminal User Setup", $longdate,0,0) ;MsgBox(64,"Terminal User Setup", $blah,0,0) exit Link to comment Share on other sites More sharing options...
Developers Jos Posted August 17, 2016 Developers Share Posted August 17, 2016 I knew what I stated in this case was correct and merely did so to explain to you'll why thing were not working as expected. 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...
ur Posted August 17, 2016 Share Posted August 17, 2016 Unlike other languages, AutoIT precedence of not operator is more. So, keep the entire content in braces and keep not outside the braces. Link to comment Share on other sites More sharing options...
SadBunny Posted August 17, 2016 Share Posted August 17, 2016 (edited) My $0.02: if you want better logging, don't implement your logging solution in every line where you want to log something. Instead, send a log string to a method and let the method decide how to log it. That way, if you decide later that you (for instance) want to log to a file instead of in msgboxes, or maybe you want to add a date to every log line, you only have to change that one little logging method instead of many many lines of logging. A modified (because self-contained) example of what I normally use: expandcollapse popup#include <File.au3> #include <Date.au3> ; ---------------------- Configure and initialize logging Global $A_LOG_LEVELS[5] = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"] ; <-- In my files this is moved into my logging library/UDF. Global $LOG_TO_MSGBOX = False ; <-- set to True to enable logging to msgboxes Global $LOG_TO_FILE = "c:\tmp\log.txt" ; leave empty or set to False for no logging to file Global $LOG_TO_CONSOLE = True Global $GLOBAL_LOG_LEVEL = "TRACE" ; Set to TRACE, DEBUG, INFO, WARN or ERROR to determine how much will be logged. Global $GLOBAL_LOG_LEVEL_INDEX = _ArraySearch($A_LOG_LEVELS, $GLOBAL_LOG_LEVEL) If $GLOBAL_LOG_LEVEL_INDEX = -1 Then MsgBox(16, "Error initializing log config", "Loglevel '" & $GLOBAL_LOG_LEVEL & "' not known in array of loglevels, or not set yet. Make sure you set the log level before calling this initialization function. Set it to any of these: " & _ArrayToString($A_LOG_LEVELS, ", ") & ". Exiting!") Exit EndIf ; ---------------------- End logging initialization ; BEGINNING OF SCRIPT logMessage("INFO", "Welcome to a new run of this script!") logMessage("DEBUG", "Starting calculation...") Local $total For $i = 1 To 5 $total = $total + $i logMessage("TRACE", "New number added to total count: " & $i & ", total now: " & $total) Next logMessage("INFO", "Calculation complete, total is: " & $total) If $total > 10 Then logMessage("WARN", "Watch out, the total is bigger than 10!") If "something" <> "else" Then logMessage("ERROR", "Two different strings are different! Help! :)") ; END OF SCRIPT ; Below is all boilerplate for logging. In my files this is all moved into my logging library/UDF. ; General method that will determine how to log what Func logMessage($level, $msg) If _ArraySearch($A_LOG_LEVELS, $level) < $GLOBAL_LOG_LEVEL_INDEX Then Return ; <-- Skip logging when the log level of the current message is below the configured threshold. If $LOG_TO_MSGBOX = True Then logToMsgbox($level, $msg) If $LOG_TO_FILE = True And $LOG_TO_FILE <> "" Then logToFile($level, $msg) If $LOG_TO_CONSOLE = True Then logToConsole($level, $msg) EndFunc ;==>logMessage ; Note: actually the check whether a logger is disabled or enabled should not be inside the logger methods. ; The logger methods should only do the logging, they should ; But this is nice and easy ; Msgbox logging implementation Func logToMsgbox($level, $msg) Local $msgboxFlag = 64 ; just use info icon If $level = "WARN" Then $msgboxFlag = 48 ; exclamation icon for warnings! If $level = "ERROR" Then $msgboxFlag = 16 ; stop-sign icon for errors! MsgBox($msgboxFlag, "Log msg", getLogPrefix($level) & $msg) EndFunc ;==>logToMsgbox ; File logging implementation. Modified/simplified version of _FileWriteLog from included File.au3! Func logToFile($level, $msg) Local $iOpenMode = $FO_APPEND $hFileOpen = FileOpen($LOG_TO_FILE, $FO_APPEND) If $hFileOpen = -1 Then MsgBox(64, "Error appending to logfile", "Error appending to log file!" & @CRLF & @CRLF & "File: " & $LOG_TO_FILE & @CRLF & "Message: " & $msg) Return EndIf Local $iReturn = FileWriteLine($hFileOpen, $msg) $iReturn = FileClose($hFileOpen) If $iReturn <= 0 Then MsgBox(64, "Error closing logfile", "Error closing log file!" & @CRLF & @CRLF & "File: " & $LOG_TO_FILE & @CRLF & "Message: " & $msg) EndIf Return $iReturn EndFunc ;==>logToFile ; Console logging implementation Func logToConsole($level, $msg) ConsoleWrite(getLogPrefix($level) & $msg & @CRLF) EndFunc ;==>logToConsole ; Define standard prefix which will be prefixed before every line of logging Func getLogPrefix($level) Return _NowCalc() & " | " & $level & ": " EndFunc ;==>getLogPrefix ... and the logging result of this example is: Quote 2016/08/18 00:27:16 | INFO: Welcome to a new run of this script! 2016/08/18 00:27:16 | DEBUG: Starting calculation... 2016/08/18 00:27:16 | TRACE: New number added to total count: 1, total now: 1 2016/08/18 00:27:16 | TRACE: New number added to total count: 2, total now: 3 2016/08/18 00:27:16 | TRACE: New number added to total count: 3, total now: 6 2016/08/18 00:27:16 | TRACE: New number added to total count: 4, total now: 10 2016/08/18 00:27:16 | TRACE: New number added to total count: 5, total now: 15 2016/08/18 00:27:16 | INFO: Calculation complete, total is: 15 2016/08/18 00:27:16 | WARN: Watch out, the total is bigger than 10! 2016/08/18 00:27:16 | ERROR: Two different strings are different! Help! Edited August 17, 2016 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. 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