BrettF Posted January 25, 2008 Share Posted January 25, 2008 (edited) Now this is strange behaviour. I noticed it today while experimenting with GeoSoft. It appears, when you delete an element using _ArrayDelete, it still manages to complete the whole array. Example 1: #include <Array.au3> Dim $avArray[10] $avArray[0] = "JPM" $avArray[1] = "Holger" $avArray[2] = "Jon" $avArray[3] = "Larry" $avArray[4] = "Jeremy" $avArray[5] = "Valik" $avArray[6] = "Cyberslug" $avArray[7] = "Nutster" $avArray[8] = "JdeB" $avArray[9] = "Tylo" $orr = UBound ($avArray) -1 For $i = 0 To UBound ($avArray) -1 ConsoleWrite ($i & "/" & $orr & " out of " & UBound ($avArray) - 1 & " possible elements" & @CRLF) If $i = 0 Then ConsoleWrite ("Element 8 (" & $avArray[8] & ") was deleted" & @CRLF) _ArrayDelete( $avArray,8) EndIf Next Now the next interesting bit is when a value is hard coded, it is able to exceed the array element total. Example: #include <Array.au3> Dim $avArray[10] $avArray[0] = "JPM" $avArray[1] = "Holger" $avArray[2] = "Jon" $avArray[3] = "Larry" $avArray[4] = "Jeremy" $avArray[5] = "Valik" $avArray[6] = "Cyberslug" $avArray[7] = "Nutster" $avArray[8] = "JdeB" $avArray[9] = "Tylo" $orr = UBound ($avArray) -1 For $i = 0 To 15 ConsoleWrite ($i & "/" & $orr & " out of " & UBound ($avArray) - 1 & " possible elements" & @CRLF) If $i = 0 Then ConsoleWrite ("Element 8 (" & $avArray[8] & ") was deleted" & @CRLF) _ArrayDelete( $avArray,8) EndIf Next That definately should have failed... Just wondered if this was a bug, or if it was intentional. Cheers Brett EDIT: XP SP2, AutoIt V3.2.10.0 Edited January 25, 2008 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
randallc Posted January 25, 2008 Share Posted January 25, 2008 huh? ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
BrettF Posted January 25, 2008 Author Share Posted January 25, 2008 Please tell me how example 2 shouldn't have failed. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
BrettF Posted January 25, 2008 Author Share Posted January 25, 2008 (edited) Of course. I'm not thinking straight. Bit of a lack of sleep. The array was never accessed, so it had no reason to fail. Duh! Don't mind me folks... EDIT: But why does $i still exceed the Ubound in the first example? EDIT 2: If I do this (My code before was all wrong. WTF was with my Ubound () -1... mmmmmm... ): #include <Array.au3> Dim $avArray[10] $avArray[0] = "JPM" $avArray[1] = "Holger" $avArray[2] = "Jon" $avArray[3] = "Larry" $avArray[4] = "Jeremy" $avArray[5] = "Valik" $avArray[6] = "Cyberslug" $avArray[7] = "Nutster" $avArray[8] = "JdeB" $avArray[9] = "Tylo" $orr = UBound ($avArray) For $i = 0 To UBound ($avArray) ConsoleWrite ($i & "/" & $orr & " out of " & UBound ($avArray) & " possible elements [" & $avArray[$i] & "]" & @CRLF) If $i = 0 Then ConsoleWrite ("Element 8 (" & $avArray[8] & ") was deleted" & @CRLF) _ArrayDelete( $avArray,8) EndIf Next It fails. Mainly from what I can see was because when you deleted the element, then Ubound wasn't updated. Is that because the value of UBound is recorded by AutoIt, then is used from there in the loop? Edited January 25, 2008 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
randallc Posted January 25, 2008 Share Posted January 25, 2008 Of course. I'm not thinking straight. Bit of a lack of sleep. The array was never accessed, so it had no reason to fail. Duh! Don't mind me folks... EDIT: But why does $i still exceed the Ubound in the first example? EDIT 2: If I do this (My code before was all wrong. WTF was with my Ubound () -1... mmmmmm... ): #include <Array.au3> Dim $avArray[10] $avArray[0] = "JPM" $avArray[1] = "Holger" $avArray[2] = "Jon" $avArray[3] = "Larry" $avArray[4] = "Jeremy" $avArray[5] = "Valik" $avArray[6] = "Cyberslug" $avArray[7] = "Nutster" $avArray[8] = "JdeB" $avArray[9] = "Tylo" $orr = UBound ($avArray) For $i = 0 To UBound ($avArray) ConsoleWrite ($i & "/" & $orr & " out of " & UBound ($avArray) & " possible elements [" & $avArray[$i] & "]" & @CRLF) If $i = 0 Then ConsoleWrite ("Element 8 (" & $avArray[8] & ") was deleted" & @CRLF) _ArrayDelete( $avArray,8) EndIf Next It fails. Mainly from what I can see was because when you deleted the element, then Ubound wasn't updated. Is that because the value of UBound is recorded by AutoIt, then is used from there in the loop?Yes, I think. You have to start at ubound-1 and go step -1 if you are going to use arraydelete in a loop... Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
BrettF Posted January 25, 2008 Author Share Posted January 25, 2008 Yes, I think.You have to start at ubound-1 and go step -1 if you are going to use arraydelete in a loop...Best, RandallOk. Thanks. I started to confuse myself... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Valik Posted January 25, 2008 Share Posted January 25, 2008 The "Stop" value is calculated once and stored. It is never re-evaluated. Link to comment Share on other sites More sharing options...
BrettF Posted January 25, 2008 Author Share Posted January 25, 2008 The "Stop" value is calculated once and stored. It is never re-evaluated.Figured that Thanks for putting up with my mindless rambles... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! 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