fede97 Posted November 28, 2014 Share Posted November 28, 2014 Hey all, i've what i suppose to be a stupid problem with this script. I've been writing my logging udf (nothing fancy, just to help me in my next scripts) and i get this error "...\Aut2Log.au3" (52) : ==> Variable used without being declared.: Func _Aut2Log_Settings($bLogging = True, $iLogOutput = $__LOG_OUTPUT, $sFile = $__LOG_STANDARDFILEPATH) Func _Aut2Log_Settings($bLogging = True, $iLogOutput = ^ ERROR My code: expandcollapse popup#include-once ; #INDEX# ======================================================================================================================= ; Title .........: Aut2Log ; AutoIt Version : 3.3.12.0 ; Language ......: English ; Description ...: Logging UDF ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Const $__A2L_OUT_CONSOLE = 1 Global Const $__A2L_OUT_FILE = 2 Global Const $__A2L_OUT_BOTH = $__A2L_OUT_CONSOLE + $__A2L_OUT_FILE Global Enum $__A2L_TYPE_MESSAGE, $__A2L_TYPE_ARRAY, $__A2L_TYPE_RETURNVALUE, $__A2L_TYPE_ENVINFO ; =============================================================================================================================== ; #INTERNAL CONFIGS# ============================================================================================================ Global $__LOG_ENABLE = False Global $__LOG_OUTPUT = $__A2L_OUT_CONSOLE If StringRight (@ScriptDir, 1) <> '\' Then Global $__LOG_STANDARDFILEPATH = @ScriptDir & StringFormat("\logs\%04i\%02i\logfile_%02i-%02i-%02i", @YEAR, @MON, @MDAY, @HOUR, @MIN) Else Global $__LOG_STANDARDFILEPATH = @ScriptDir & StringFormat("logs\%04i\%02i\logfile_%02i-%02i-%02i", @YEAR, @MON, @MDAY, @HOUR, @MIN) EndIf ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_Aut2Log_Settings ;_Aut2Log_WriteEnvironment ;_Aut2Log_Write ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _Aut2Log_Settings ; Description ...: Configure logging options ; Syntax.........: _Aut2Log_Settings($bLogging [, $sFile = $__LOG_STANDARDFILEPATH]) ; Parameters ....: $bLogging - Enable/Disable logging ; $iLogOutput - $__A2L_OUT_CONSOLE = Output to console (Default) ; | $__A2L_OUT_FILE = Output to file ; | $__A2L_OUT_BOTH = Output to both ; $sFile - [optional] Logfile path, if not present and file logging is enabled python's logging rules ; will be used ; Return values .: Success - @error = 0 ; Failure - How is this even possible? You failed really bad man... ; Author ........: fede.97 ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _Aut2Log_Settings($bLogging = True, $iLogOutput = $__LOG_OUTPUT, $sFile = $__LOG_STANDARDFILEPATH) $__LOG_ENABLE = $bLogging $__LOG_OUTPUT = $iLogOutput $__LOG_STANDARDFILEPATH = $sFile Return SetError (0) EndFunc ;==>_Aut2Log_Settings ; #FUNCTION# ==================================================================================================================== ; Name...........: _Aut2Log_WriteEnvironment ; Description ...: Configure logging options ; Syntax.........: _Aut2Log_WriteEnvironment(ByRef $avAnArray, $iAnInt[, $hAHandle = 0[, $nSomeNumber = 42]]) ; Parameters ....: $avAnArray - [byref] An array of anything. The value of anything is changed and passed out using this ; parameter. The array should only have one dimension ; $iAnInt - An integer that does very little. ; $hAHandle - [optional] A handle. Default is zero. ; $nSomeNumber - [optional] A number of some kind. Default is 42. ; Return values .: Success - A MYSTRUCT structure. ; Failure - Returns zero and sets the @error flag: ; |1 - The $avAnArray is invalid. ; Author ........: fede.97 ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _Aut2Log_WriteEnvironment() $sEnvStats = '<Autoit>' & @CRLF & _ 'Compiled: ' & @OSBuild = 1 & @CRLF & _ 'ScriptFullPath: ' & @ScriptFullPath & @CRLF & _ 'AutoItVersion: ' & @AutoItVersion & @CRLF & _ 'AutoItX64: ' & @AutoItX64 = 1 & @CRLF & _ '<Current User Directory>' & @CRLF & _ 'AppDataDir: ' & @AppDataDir & @CRLF & _ 'DesktopDir: ' & @DesktopDir & @CRLF & _ 'UserProfileDir: ' & @UserProfileDir & @CRLF & _ 'HomeDrive: ' & @HomeDrive & @CRLF & _ 'ProgramFilesDir: ' & @ProgramFilesDir & @CRLF & _ 'SystemDir: ' & @SystemDir & @CRLF & _ 'TempDir: ' & @TempDir & @CRLF & _ '<System>' & @CRLF & _ 'CPUArch: ' & @CPUArch & @CRLF & _ 'KBLayout: ' & @KBLayout & @CRLF & _ 'OSLang: ' & @OSLang & @CRLF & _ 'OSVersion: ' & @OSVersion & @CRLF & _ 'OSBuild: ' & @OSBuild & @CRLF & _ 'ComputerName: ' & @ComputerName & @CRLF & _ 'UserName: ' & @UserName & @CRLF & _ 'OSBuild: ' & @OSBuild & @CRLF _Aut2Log_Write($sEnvStats, $__A2L_TYPE_ENVINFO) EndFunc ;==>_Aut2Log_WriteEnvironment ; #FUNCTION# ==================================================================================================================== ; Name...........: _Aut2Log_Write ; Description ...: Configure logging options ; Syntax.........: _Aut2Log_Write(ByRef $avAnArray, $iAnInt[, $hAHandle = 0[, $nSomeNumber = 42]]) ; Parameters ....: $avAnArray - [byref] An array of anything. The value of anything is changed and passed out using this ; parameter. The array should only have one dimension ; $iAnInt - An integer that does very little. ; $hAHandle - [optional] A handle. Default is zero. ; $nSomeNumber - [optional] A number of some kind. Default is 42. ; Return values .: Success - ... ; Failure - ... ; Author ........: fede.97 ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _Aut2Log_Write(ByRef $sMessage, $iOutType, $sOutFile = $__LOG_STANDARDFILEPATH, $bOverride = False) If $__LOG_ENABLE = False Or $bOverride = False Then Return Switch $iOutType Case $__A2L_TYPE_ENVINFO Local $sLine = 'ENVIRONMENT INFO' & @CRLF & '[' & @HOUR & ':' & @MIN & ':' & @SEC &'] "' & $sMessage & '"' EndSwitch Switch $__LOG_OUTPUT Case $__A2L_OUT_CONSOLE ConsoleWrite ($sLine) ;~ Case ;~ Case EndSwitch EndFunc ;==>_Aut2Log_Write It's really simple and, of course, incomplete but i'm stuck. Any help would be greatly appreciated Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted November 28, 2014 Moderators Solution Share Posted November 28, 2014 fede97l,Do you add this include file to you script after you call the _Aut2Log_Settings function for the first time? That would explain the problem as AutoIt requires variables to be declared before they are used. M23 fede97 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...
fede97 Posted November 28, 2014 Author Share Posted November 28, 2014 (edited) I'm not even using it in another script. I'm just inserting _Aut2Log_Settings() after the #include-once like this #include-once _Aut2Log_Settings() ; #INDEX# ======================================================================================================================= ; Title .........: Aut2Log ; AutoIt Version : 3.3.12.0 ; Language ......: English ; Description ...: Logging UDF ; =============================================================================================================================== ... Jibba Jabba... --Edit-- Oh, by the way, i'm using the latest autoit stable version --Edit2-- I hate myself. Told you i was missing something stupid and i realized right now my error! :ranting: Really sorry, thanks and goodbye Edited November 28, 2014 by fede97 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2014 Moderators Share Posted November 28, 2014 fede97,Been there - got the tee-shirt! M23 fede97 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...
fede97 Posted November 28, 2014 Author Share Posted November 28, 2014 May i ask another thing here just to avoid creating another topic for a simple question? Is there any potential problem using OnAutoItExitRegister in and UDF to close a file handle? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2014 Moderators Share Posted November 28, 2014 fede97,In principle: No. I use that function in a couple of my UDFs to clear up (see the NoFocusLines link in my sig). But you need to make sure that the necessary parameters are available as Global variables. M23 fede97 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...
fede97 Posted November 28, 2014 Author Share Posted November 28, 2014 Perfect, i'll have a look at your UDF. Thanks again Link to comment Share on other sites More sharing options...
guinness Posted November 29, 2014 Share Posted November 29, 2014 If the variables are only used within a single function, but need to be retained after the initial function call, then Local Static is a better option of the two than Global. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
fede97 Posted November 30, 2014 Author Share Posted November 30, 2014 (edited) Sorry but I've just seen your post. If i'm not mistaken you're telling me to use a Local instead of a Global but since i'm creating the fileopen handle inside a function, wouldn't fileclose fail if i declare the handle as local? Am i missing something? Edited November 30, 2014 by fede97 Link to comment Share on other sites More sharing options...
kylomas Posted November 30, 2014 Share Posted November 30, 2014 Depends on where you close it. If you are creating the file handle in a function and using it outside of that function then it has to be global in scope. Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
fede97 Posted November 30, 2014 Author Share Posted November 30, 2014 Yes, it's used outside of the function which created it 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