DannyJ Posted July 13, 2021 Share Posted July 13, 2021 I declared a const array, that I won't change and I can not change in the entire program. (Safety) Exept one point, one point I need to change this variable. My question is that can I delete the const variable and redeclare it? Or I need to remove Const to change the variable. If I remove const how can I make my variable "safe", because this variable can not be changed only the declaration and one point in the whole program. Thanks in advance! Link to comment Share on other sites More sharing options...
Nine Posted July 13, 2021 Share Posted July 13, 2021 You cannot redefine/delete a Const within the same scope. But you can if you change the scope too. #include <Array.au3> Global Const $aConst[3] = [1,2,3] _ArrayDisplay($aConst) DoIt() Func DoIt() Local $aConst[4] = [4,5,6,7] _ArrayDisplay($aConst) EndFunc This is one way to override the previous declaration of a variable. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
water Posted July 13, 2021 Share Posted July 13, 2021 Setting a variable/Array to Const is kind of a security measure to prevent unintended modification. Remove Const and do the "security" checking yourself. When you are ready to put your script into production scan the code for the name of the array and make sure that none of the found lines changes the array. Have a careful look at parameters as the name of the array parameter might change. Earthshine 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
LarsJ Posted July 13, 2021 Share Posted July 13, 2021 #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) Example() Func Example() Local $oDict = ObjCreate( "Scripting.Dictionary" ) $oDict.Item( "Int" ) = 1 $oDict.Item( "Flt" ) = 1.1 $oDict.Item( "Str" ) = "One" Local Const $aArray[1] = [ $oDict ] ; Local Const $oDict = 0 ConsoleWrite( "$aArray[0].Item( ""Int"" ) = " & $aArray[0].Item( "Int" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Flt"" ) = " & $aArray[0].Item( "Flt" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Str"" ) = " & $aArray[0].Item( "Str" ) & @CRLF & @CRLF ) Local $oMyDict = $aArray[0] $oMyDict.Item( "Int" ) = 2 $oMyDict.Item( "Flt" ) = 2.2 $oMyDict.Item( "Str" ) = "Two" $oMyDict = 0 ConsoleWrite( "$aArray[0].Item( ""Int"" ) = " & $aArray[0].Item( "Int" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Flt"" ) = " & $aArray[0].Item( "Flt" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Str"" ) = " & $aArray[0].Item( "Str" ) & @CRLF & @CRLF ) EndFunc Console output: $aArray[0].Item( "Int" ) = 1 $aArray[0].Item( "Flt" ) = 1.1 $aArray[0].Item( "Str" ) = One $aArray[0].Item( "Int" ) = 2 $aArray[0].Item( "Flt" ) = 2.2 $aArray[0].Item( "Str" ) = Two mLipok and Earthshine 2 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
argumentum Posted July 13, 2021 Share Posted July 13, 2021 5 hours ago, DannyJ said: how can I make my variable "safe" Well, you're the coder. Declaring a value, is a value. If you where, in say C, the Const goes in a different memory space than a variable but, you're in AutoIt. Here it makes no difference. Just don't overwrite/assign other values to it. That's all. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. 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