Jump to content

Global declare as function standard parameter


fede97
 Share

Go to solution Solved by Melba23,

Recommended Posts

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:

#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

  • Moderators
  • Solution

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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: :ranting:

Really sorry, thanks and goodbye :oops:

Edited by fede97
Link to comment
Share on other sites

  • Moderators

fede97,

Been there - got the tee-shirt! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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? :oops:

Edited by fede97
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...