Sign in to follow this  
Followers 0
MyEarth

Improve my Array script

2 posts in this topic

Hello guys, i'll examplain my situation and i'll post an example script:

1) I have a list of name, is an array

2) I need to take this name list and take only some name based on a rules

3) Based on the name, i need to add other values

4) The result i want to make is one array ( or more then one ) but fastest as possible, without using Redim or thing like that

This is what i have make:

#include <Array.au3>

Global $aFileList[5] = [4, "TEMP2", "NAME3", "TEMP4", "NAME5"]

Local $str = ''
For $i = 1 To $aFileList[0]
    If StringInStr($aFileList[$i], "NAME") Then
        $str &= $aFileList[$i] & '|'
    EndIf
Next

Local $aMyList = StringSplit(StringTrimRight($str, 1), '|')

If IsArray($aMyList) Then
    If $aMyList[0] = "0" Then
        Exit
    EndIf
EndIf

If IsArray($aMyList) Then
    Global $aFinal[UBound($aMyList)][4] = [[$aMyList[0], 4]]
    For $i = 1 To $aMyList[0]
        $aFinal[$i][0] = $aMyList[$i]
        $aFinal[$i][1] = "Value_" & $i
        $aFinal[$i][2] = "Value_" & $i
        $aFinal[$i][3] = "Value_" & $i
    Next
EndIf

_ArrayDisplay($aFileList, "The complete list")
_ArrayDisplay($aMyList, "The element i need")
_ArrayDisplay($aFinal, "The final result with other values based on the first") ;<<< I need only this

There is a way to improve it, make it short or remove some unseless steps?

Share this post


Link to post
Share on other sites

... another way .....

#include <Array.au3>

Global $aFileList[5] = [4, "TEMP2", "NAME3", "TEMP4", "NAME5"]

$query = "NAME"

$ndx = _ArrayFindAll($aFileList, $query, 1, 0, 0, 1)

If Not @error Then
    Global $aFinal[UBound($ndx) + 1][4] = [[UBound($ndx), 4]]
    For $i = 1 To UBound($ndx)
        $aFinal[$i][0] = $aFileList[$ndx[$i - 1]]
        $aFinal[$i][1] = "Value_" & $i
        $aFinal[$i][2] = "Value_" & $i
        $aFinal[$i][3] = "Value_" & $i
    Next
    _ArrayDisplay($aFinal, "The final result with other values based on the first")
Else
    Exit
EndIf

bye


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0