hispeed_mike Posted August 30, 2007 Share Posted August 30, 2007 Hi, Hre is my code thus far, I have spent hours pulling my hair out to try and understand a loop, and how to manage this array. Thanks in advance What I am trying to do is to load an array from a text file which is no problem. The text in this file is individual account names. After each of the account names is used I will be writing an "x" to the end of the line. Each time the array is loaded I want to exclude the ones with "x" on the end and only display the others inside of a combo box we use. This way one account name won't get used a second time. The GUI for the combo box not included. I just need help with this loop. Originally there was a message box in place for the arraydelete command which would tell me which lines had the "x" on the ned and it worked. Since changing this to _ArrayDelete I get "Array variable has incorrect number of subscripts Error....". Please if t all possible a little explaination on what I am missing here. I have read help not finding anything I thought to be relevant. I really really want to understand loops. #include "Process.au3" #include "ControlSendPlus.au3" #include <GUIConstants.au3> #include <file.au3> #Include <Array.au3> Dim $aAccounts If Not _FileReadToArray(@SCRIPTDIR & "\any.txt", $aAccounts) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $i = "x" ; MsgBox (4096, "EA Account Names", $accresult) For $x = 1 To $aAccounts[0] ;loops through each line in the text file If StringInStr($aAccounts[$x], $i) Then ;reads each line of the file for the search $Line = $x MsgBox (4096, "Variable", $Line) _ArrayDelete ($aAccounts,$Line) EndIf Next Link to comment Share on other sites More sharing options...
martin Posted August 30, 2007 Share Posted August 30, 2007 Hi, Hre is my code thus far, I have spent hours pulling my hair out to try and understand a loop, and how to manage this array. Thanks in advance What I am trying to do is to load an array from a text file which is no problem. The text in this file is individual account names. After each of the account names is used I will be writing an "x" to the end of the line. Each time the array is loaded I want to exclude the ones with "x" on the end and only display the others inside of a combo box we use. This way one account name won't get used a second time. The GUI for the combo box not included. I just need help with this loop. Originally there was a message box in place for the arraydelete command which would tell me which lines had the "x" on the ned and it worked. Since changing this to _ArrayDelete I get "Array variable has incorrect number of subscripts Error....". Please if t all possible a little explaination on what I am missing here. I have read help not finding anything I thought to be relevant. I really really want to understand loops. #include "Process.au3" #include "ControlSendPlus.au3" #include <GUIConstants.au3> #include <file.au3> #Include <Array.au3> Dim $aAccounts If Not _FileReadToArray(@SCRIPTDIR & "\any.txt", $aAccounts) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $i = "x" ; MsgBox (4096, "EA Account Names", $accresult) For $x = 1 To $aAccounts[0] ;loops through each line in the text file If StringInStr($aAccounts[$x], $i) Then ;reads each line of the file for the search $Line = $x MsgBox (4096, "Variable", $Line) _ArrayDelete ($aAccounts,$Line) EndIf Next You are looping through to the number of elements in the array which exist at the start, but as soon as you delete an element you will have to stop the loop one sooner because there are now fewer elements. The way out of this is to run the loop backwards. start at the end then when you delete one it doesn.t matter. For $x = $aAccounts[0] to 1 step -1;loops through each line in the text file If StringInStr($aAccounts[$x], $i) Then;reads each line of the file for the search $Line = $x MsgBox (4096, "Variable", $Line) _ArrayDelete ($aAccounts,$Line) EndIf Next Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
MrCreatoR Posted August 30, 2007 Share Posted August 30, 2007 The problem with _ArrayDelete() is that after deletion the zero-based element not seted to general elemnts count..Before SetError(0) at the end of this function should be this line:$avArray[0] = UBound($avNewArray)-1 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
martin Posted August 30, 2007 Share Posted August 30, 2007 The problem with _ArrayDelete() is that after deletion the zero-based element not seted to general elemnts count.. Before SetError(0) at the end of this function should be this line: $avArray[0] = UBound($avNewArray)-1Agreed, but that wouldn't help hispeed_mike because the end value of his loop is set to UBound($aAccounts) and when elements are deleted that end value is incorrect, but by looping 'backwards' it doen't matter. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ssubirias3 Posted August 30, 2007 Share Posted August 30, 2007 The way out of this is to run the loop backwards. start at the end then when you delete one it doesn.t matter.Couldn't something like this also work instead of running it backwards? Do ;... some code Until UBound($aAccounts) = 1 The idea comes from a post PsaltyDS made on something I was working on a while back. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 30, 2007 Share Posted August 30, 2007 Couldn't something like this also work instead of running it backwards? Do ;... some code Until UBound($aAccounts) = 1 The idea comes from a post PsaltyDS made on something I was working on a while back. That won't help in the case where the code at ";... some code" is deleting elements from the array. Looping through backwards (ala Martin) is the right answer. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
hispeed_mike Posted August 30, 2007 Author Share Posted August 30, 2007 Hi Again, with the endif in place it runs fine, The reverse order is returning nearly what I wanted. Th only issue I have with this so far is the Array also returns a [0] position as well which from what I can work out is the amount of entries in the array. I need to be able to return this array as a variable I can use in a combobox without the $aArray[0] entri being listed. Here is how I am listing the array $accounts = _ArrayToString ($aAccounts, "|") Using the delimiter to allow a combobox to list it properly. It also seems that if I try to use _ArrayDelete ($aAccounts, 0) nothing then displays, I would assume that doing this would delete the index of the array and then not display anything, woudl I be right in saying that? Thanks Mike Link to comment Share on other sites More sharing options...
hispeed_mike Posted August 30, 2007 Author Share Posted August 30, 2007 Hi Again, with the endif in place it runs fine, The reverse order is returning nearly what I wanted. Th only issue I have with this so far is the Array also returns a [0] position as well which from what I can work out is the amount of entries in the array. I need to be able to return this array as a variable I can use in a combobox without the $aArray[0] entri being listed. Here is how I am listing the array $accounts = _ArrayToString ($aAccounts, "|") Using the delimiter to allow a combobox to list it properly. It also seems that if I try to use _ArrayDelete ($aAccounts, 0) nothing then displays, I would assume that doing this would delete the index of the array and then not display anything, woudl I be right in saying that? Thanks Mike Not to worry, If I had just spent a moment more on the _Array to string command I would have realize the next thing I can add is which line to start from... eg. $accounts = _ArrayToString ($aAccounts, "|", 1) Thanks All for comments.... Mike 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