seadoggie01 Posted November 8, 2019 Share Posted November 8, 2019 (edited) How do we wipe a static array without resizing the elements? I've gotten errors each time I've tried. Background: I'm attempting an error stack because I'm lazier than water... I don't want to make all my error numbers unique. I also realized that I needed to resize the array to 0 since I'm returning the whole stack, but now I'm curious if this is possible. Func __ErrorStack($iError = 0, $sFunction = "") ; The static error stack Static $aErrors[0] ; If the user wants the stack If $iError = 0 Then ; Copy the errors Local $aRet = $aErrors ; Clear the error stack <Keyword> $aErrors[1] ;<--- Error line ; Return the error stack Return $aRet ; Otherwise, I'm adding an error Else ; Resize ReDim $aErrors[UBound($aErrors) + 1] ; And add $aErrors[UBound($aErrors) - 1] = $sFunction & ":" & $iError EndIf EndFunc I wasn't sure, so I tested. ; I really expected Static to work... the variable already is static... why is it trying to make it static again? Static $aErrors[1] ; Cannot make existing variables static. ReDim $aErrors[1] ; Works... but doesn't clear the first element Local $aErrors[1] ; Cannot make static variables into regular variables. Dim $aErrors[1] ; Cannot make static variables into regular variables. ; These repeat their respective errors above Static $aErrors Local $aErrors Dim $aErrors Is this possible with static arrays? I can think of two solutions: ReDim to 0 and ReDim back up to the original, but that seems weird. Declare and overwrite with a second variable, again, that seems clunky Edited November 8, 2019 by seadoggie01 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Nine Posted November 8, 2019 Share Posted November 8, 2019 This ? #include <Array.au3> _Stack (2) _Stack (5) _Stack (0) _stack (2) Func _Stack ($iNum) Static $aErrors[1] = ["Test"] ReDim $aErrors[$iNum] _ArrayDisplay ($aErrors) EndFunc “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...
seadoggie01 Posted November 8, 2019 Author Share Posted November 8, 2019 Never mind. I realized I'm thinking in VBA again where using Dim a second time will create an array of the same size with empty elements. Sorry about that. I've been using Macros too much lately All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Nine Posted November 8, 2019 Share Posted November 8, 2019 2 minutes ago, seadoggie01 said: Sorry about that No need to be sorry. Happens... “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...
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