guinness

An example of protecting a variable(s) that should be global throughout the application

8 posts in this topic

#1 ·  Posted (edited)

An example (or one variation at least) that I created in a discussion we (devs/mods) were having about protecting global variables.

; An enumeration for the getters and setters, as I hate having to write zero and one
Global Enum $VERSION_WRAPPER_GET, $VERSION_WRAPPER_SET

; Unused, as I have hidden behind functions, so users who might feel the need to do this $g_iVersion = 'Haha, I''m no a number', can't!
; Global $g_iVersion = 0

; Basically this is encapsulation and is just one of many principals found in Object Oriented Programming (OOP)

; NOTE: There is no way for me to access the "global" version variable without using the _Get/Set_Version() function(s)

Example()

Func Example()
    ; Set to 10, as only integer datatypes are allowed
    _Set_Version(10)

    ; Displays 10
    ConsoleWrite('1. ' & _Get_Version() & @CRLF)

    ; Set to a non-digit. Such a bad user/dev!
    _Set_Version('Not a number')

    ; Displays 10, as a string was passed previously that wasn't valid
    ConsoleWrite('2. ' & _Get_Version() & @CRLF)

    ; Call another function to show that it's not just visible within this function
    Another_Func()

    ; Displays 99, which was previously set in the Another_Func()
    ConsoleWrite('4. ' & _Get_Version() & @CRLF)

    ; If the variable located in __Version_Wrapper() was purely a global variable, then anything could be assigned to it
    ; without proper checking. As you can see below, the variable is only assigned to when certain criteria is met

    ; Before someone mentions performance, you have to weigh up the pros and cons of such a design choice. If you really need data to be protected
    ; from your users mingling with it, then this is one of many correct approaches to encapsulate data. Otherwise if you're not concerened, then
    ; maybe it's not for you. You're the developer when it comes down to it
EndFunc   ;==>Example

Func Another_Func()
    ; Displays 10
    ConsoleWrite('3. ' & _Get_Version() & @CRLF)

    ; Set to 99 and return back to the previous function i.e. Example()
    _Set_Version(99)
EndFunc   ;==>Another_Func

; Getter
Func _Get_Version()
    Return __Version_Wrapper($VERSION_WRAPPER_GET)
EndFunc   ;==>_Get_Version

; Setter
Func _Set_Version($iVersion)
    Return __Version_Wrapper($VERSION_WRAPPER_SET, $iVersion)
EndFunc   ;==>_Set_Version

; This is a wrapper for the local static variable that will be visible only in the function and for the duration of the application's
; lifecycle

; $iType: Either $VERSION_WRAPPER_GET or $VERSION_WRAPPER_SET
; $iVersion: Used when the type is $VERSION_WRAPPER_SET
Func __Version_Wrapper($iType, $iVersion = Null)
    ; Create a local static variable and initialise to 0
    Local Static $s_iVersion = 0

    Switch $iType
        Case $VERSION_WRAPPER_GET ; Getter
            Return $s_iVersion

        Case $VERSION_WRAPPER_SET ; Setter
            ; Now is the chance to check if the value meets certain criteria e.g. [0-9]+ and not a string datatype
            If StringRegExp($iVersion, '^\d+$') And Not IsString($iVersion) Then
                $s_iVersion = $iVersion
            EndIf

    EndSwitch

    ; Return null by default, especially if the type is as a setter
    Return Null
EndFunc   ;==>__Version_Wrapper

 

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites



Oh yes, I do so for a year.

Good example.

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Oh yes, I do so for a year.

Good example.

 

Excellent news


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

This example is using a local static datastore i.e. having more than one variable doesn't require multiple static variables, just one is suffice. You will also notice I've excluded the ability to set the version of the application. Which of course can't be done if this was a global variable!

; An enumeration for the getters and setters, as I hate having to write zero and one
Global Enum Step * 2 $APP_GETTER, $APP_SETTER

; An enumeration for the different settings
Global Enum $APP_SETTINGS_ISFIRSTRUN, $APP_SETTINGS_NAME, $APP_SETTINGS_VERSION, $APP_SETTINGS_MAX

Example()

Func Example()

    ; Displays myAppName
    ConsoleWrite('1. ' & _Get_Name() & @CRLF)

    ; Set to a new name
    _Set_Name('A_New_Name')

    ; Displays 'A_New_Name'
    ConsoleWrite('2. ' & _Get_Name() & @CRLF)

    ; Displays 99.100.99.1
    ConsoleWrite('3. ' & _Get_Version() & @CRLF)

    ; Set to a new name
    _Set_Name('')

    ; Displays 'A_New_Name', as the string was empty previously
    ConsoleWrite('4. ' & _Get_Name() & @CRLF)

    ; If the variable located in __AppSettings_Wrapper() was purely a global variable, then anything could be assigned to it
    ; without proper checking. As you can see below, the variable is only assigned to when certain criteria is met

    ; Before someone mentions performance, you have to weigh up the pros and cons of such a design choice. If you really need data to be protected
    ; from your users mingling with it, then this is one of many correct approaches to encapsulate data. Otherwise if you're not concerened, then
    ; maybe it's not for you. You're the developer when it comes down to it
EndFunc   ;==>Example

; Getter
Func _Get_Name()
    Return __AppSettings_Wrapper($APP_GETTER, $APP_SETTINGS_NAME)
EndFunc   ;==>_Get_Name

; Setter
Func _Set_Name($sName)
    Return __AppSettings_Wrapper($APP_SETTER, $APP_SETTINGS_NAME, $sName)
EndFunc   ;==>_Set_Name

; Getter
Func _Get_Version()
    Return __AppSettings_Wrapper($APP_GETTER, $APP_SETTINGS_VERSION)
EndFunc   ;==>_Get_Version

; This is a wrapper for the local static variable that will be visible only in the function and for the duration of the application's
; lifecycle

; $iGetterOrSetter: Either $APP_GETTER or $APP_SETTER
; $iType: The parameter type e.g. name, version etc...
; $vValue: Used when the type is $APP_SETTER
Func __AppSettings_Wrapper($iGetterOrSetter, $iType, $vValue = Null)
    ; Create a local static variable and initialise to 0
    Local Static $s_aAppSettings[$APP_SETTINGS_MAX] = [True] ; First element is $APP_SETTINGS_ISFIRSTRUN

    ; If the first run, then initialise the $s_aAppSettings array with default values
    If $s_aAppSettings[$APP_SETTINGS_ISFIRSTRUN] Then
        $s_aAppSettings[$APP_SETTINGS_ISFIRSTRUN] = False ; Set to false, as now the array has been initialised
        $s_aAppSettings[$APP_SETTINGS_NAME] = 'myAppName'
        $s_aAppSettings[$APP_SETTINGS_VERSION] = '99.100.99.1'
    EndIf

    Switch $iGetterOrSetter
        Case $APP_GETTER ; Getter
            Switch $iType
                Case $APP_SETTINGS_NAME
                    Return $s_aAppSettings[$APP_SETTINGS_NAME]

                Case $APP_SETTINGS_VERSION
                    Return $s_aAppSettings[$APP_SETTINGS_VERSION]

            EndSwitch

        Case $APP_SETTER ; Setter
            Switch $iType
                Case $APP_SETTINGS_NAME
                    If $vValue Then
                        $s_aAppSettings[$APP_SETTINGS_NAME] = $vValue
                    EndIf

                Case $APP_SETTINGS_VERSION
                    ; No setter for the version attribute

            EndSwitch

    EndSwitch

    ; Return null by default, especially if the type is as a setter
    Return Null
EndFunc   ;==>__AppSettings_Wrapper

 


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

One question:

; An enumeration for the getters and setters, as I hate having to write zero and one
Global Enum Step * 2 $APP_GETTER, $APP_SETTER

Why you are using Step * 2 ?

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Just felt like it, as I wanted to showcase something different from the first example


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

But this is very intresting , I've never used multiplication in enums steps. 
Now I see that in this way I can make a "BIT masked" enums.

I think I have an idea of new example to HelpFile, but first I must play a litle with it.

Thanks.


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Okay great


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

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

  • Similar Content

    • TheDcoder
      By TheDcoder
      Hello everyone, I discovered a bug yesterday and I posted it at the bug tracker:
      I also made a simple script which can be used to reproduce the bug:
      CreateVariable() ConsoleWrite($sGlobalVariable & @CRLF) Func CreateVariable() Global $sGlobalVariable = "Foobar" EndFunc The bug was closed by @BrewManNH:
      While I partially agree with the above statement, My code was not practical enough... so @mLipok advised me to create a thread on the forums with practical code (Thanks!). That is the point of this thread, I am going to provide the code where I experience this bug/problem .
      I discovered this bug when I was working on one of my projects called "ProxAllium". When the main script finishes execution, Au3Check throws a nasty warning about "variable possibly used before declaration":

      As you can see, the variable is indeed being used after calling the function in which the variable is declared... The warning won't appear if I declare the function ABOVE the variable. As @BrewManNH said, Au3Check reads line by line... I think this should be changed, Au3Check should not throw warnings if the interpreter is able to run the code, at least most of the time anyway!
      So what do you guys think? Is this a valid bug?... and I request those who participate in the discussion not to discuss the code being "poor", that is another thing/thread in itself
      P.S I had already written this once but the forum editor decided to mess up and when I undid (Ctrl + Z) something... This is a poorly written version of that article, I was very frustrated while writing this!
    • PELock
      By PELock
      I'm trying to use #OnAutoItStartRegister to modify the Global variable, but it seems it doesn't work, is that on purpose, that those callback functions cannot modify anything except in their own scope?
    • Relive
      By Relive
      This is the error message I got: "Cannot make existing variables static."
      I'm trying to use static variable as a means to iterate a section of my script. 
      Original
      Edit1
      while 1 global $initial, $constant = 1 $x = $initial + ($constant * SomeFunc()) msgbox(0, '', $x) wend func SomeFunc() global static $counter = -1 $counter += 1 return $counter endfunc  
    • Ascend4nt
      By Ascend4nt
      Atom Table UDF
      Local and Global Atom Table

      Since I've had this collecting dust on my computer, I figured I'd release it to see if anyone can find some use for it.
      About Atom Tables - MSDN

      Example Global Atom Table Listing
       
      Basically, a bunch of strings can be stored locally (at program level) or globally (at O/S level) with unique numerical identifiers. This UDF lets you add, find, delete, and query these atoms.
       
      Description from the top of the AtomFunctions UDF:
      ----------------------------------------------------------------
      Functions for accesing Local and Global Atom Tables, which contain strings up to 255 characters long
      The Atom tables are used for multiple types of Windows data including Window Classes (RegisterClass/Ex), Clipboard formats (RegisterClipboardFormat), Hotkeys (RegisterHotKey), and Dynamic Data Exchange (DDE) which is a form of interprocess communication. (Some of the above may use a Local rather than the Global Atom table)
      Other uses can include storing program strings to lookup by a 16-bit value and interprocess communication

       "RegisterHotKey function" @ MSDN states this:
       "An application must specify an id value in the range 0x0000 through 0xBFFF.
        A shared DLL must specify a value in the range 0xC000 through 0xFFFF
        (the range returned by the GlobalAddAtom function).
        To avoid conflicts with hot-key identifiers defined by other shared DLLs,
        a DLL should use the GlobalAddAtom function to obtain the hot-key identifier."

       Kernel Note: The Atom Table is a separate entity from Kernel Objects like Events, Mutexes, Files, etc.  However, the Atom Table is (separately) accessible from within the Kernel, so its like a Kernish object?

      Notes on Atom Tables:
      Stringlimit is 255 characters NOT including a null-terminator. This is unfortunately not   enough for a MAX_PATH string, which is 259+null-term. However, stripping off root-drive prefix get you within 1 character of the length (259 - 3 ["C:"] = 256] which may be enough - but using IPC, one can store 4 - 6 (8-12 in x64) extra chars in wParam/lParam..   See <AtomExample_IPC.au3> for an implementation of this  
      There is both a Local and Global Atom Table. The Local one is local to this Process,   and the Global one is available/accessible to/from all Processes.  
      Atoms numbered 0 - 49151 (0xBFFF) are not actually part of the Atom Table.   Querying these values will return a string representation of the number as an unsigned integer    Example: 1234 is translated to "#1234"
       
      Adding atom strings that start with a "#" will return an unsigned integer if the numbers   following "#" are an integer less than 49152 (1 - 49151 [0xBFFF]).     Examples: "#1" => 1, "#49151" => 49151
       
      Atoms numbered from 49152 - 65535 (from 0xC000 - 0xFFFF) DO reference the Atom Table strings  
      Maximum Atom string length is 255 characters (not including a null-terminator)  
      Functions:
      ;  Local: ;    _AtomTableInit()        ; Initializes Local Atom Table. Optional [37 hash buckets allocated by default] ;    _AtomAddLocal()            ; Adds a string to the Local Atom table, returns # identifier [increments reference if already exists] ;    _AtomGetNameLocal()        ; Gets the Local Atom string associated with a numerical identifier ;    _AtomDeleteLocal()        ; Decrements the reference count of Local Atom, deletes when reaches 0 ;    _AtomFindLocal()        ; Finds # identifier for a string in the Local Atom table ;    _AtomGetAllLocal()        ; Returns all found Local atoms in an array ; Global: ;    _AtomAddGlobal()        ; Adds a string to the Global Atom table, returns # identifier [increments reference if already exists] ;    _AtomGetNameGlobal()    ; Gets the Global Atom string associated with a numerical identifier ;    _AtomDeleteGlobal()        ; Decrements the reference count of Global Atom, deletes when reaches 0 ;    _AtomFindGlobal()        ; Finds # identifier for a string in the Global Atom table ;    _AtomGetAllGlobal()        ; Returns all found Global atoms in an array ; 'Undocumented': ;    _AtomGetGlobalTableUD() ; Using 'undocumented' function calls, gets info on all Global Atoms ;    _AtomGetInfoUD()        ; Returns reference count, pinned status, as well as Atom Name ----------------------------------------------------------------
      There are a few 'undocumented' functions used for getting information on the Atom Table included (I can't help myself).
      In addition to the core UDF, there's 2 example files:
      AtomTableExample.au3 - This demonstrates various use - adding, deleting, and querying information in the Local and Global atom tables. (Extended info comes from 'undocumented' functions)  
      AtomExample_IPC.au3 - This demonstrates how the Atom Table could be used in InterProcess Communication. A rather rough sketch, but shows how you could squeeze MAX_PATH pathnames into IPC messages combined with Atom tables. It's all a bit light on the documentation, but I just wanted to prevent this thing from collecting more dust   Might prove useful to someone!
      History::



      AtomTablesUDF.zip ~prev Downloads: 29
       
    • Apples292
      By Apples292
      Hi everyone,
      Using this script (it has a broken link but here are the files) I'm trying to record a short clip 1 second or shorter longer (although you can assume it's always 1 second) and every time I record the clip (mp3 however it's the same on wav) it ends up with an extremely short static sound at the start of each clip even with the highest quality sound. Is there anyway you can trim the file down, also using bass, for example taking the first 100 miliseconds off the start (it has to be mp3 though)? Or on the other hand, does anyone know of another bass recording tool that allows that diversity of options, e.g quality (not essential but preferable), volume and microphone choices (these two are important) which doesn't have this issue?
      Thanks
      Apples292