Jump to content

Recommended Posts

Posted

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

Posted

  hispeed_mike said:

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.
Posted

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

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  MsCreatoR said:

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
Agreed, 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.
Posted

  martin said:

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.

Posted

  ssubirias3 said:

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
Posted

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

Posted

  hispeed_mike said:

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...