Jump to content

Dynamically Create Array's


Recommended Posts

Hi,

i've search, tried and what ever came into my mind, but i did not found a solution.

I have a textfile with peridically repeating words.

i.e.:

<Menu-ID="Programs">

<Menu-ID="Tools">

<Menu-ID="Network">

and so on.

$a=0
$file = FileOpen("D:\hover.cfg", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

;Get the number of lines from file
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $a=$a+1
Wend

For $i=1 To $a
    $readline = FileReadLine($file, $i)
    If StringInStr($readline, "Menu ID=", 2) Then
        MsgBox (0, "Test", $readline)
        %CREATE DYNAMICALLY ARRAY POSSIBLE?%
    EndIf
Next

Within the For/Next Loop, i need to create allways an new array if the matching string is found. I tried

dim $newarray & $i to get an array called $newarray1, $newarray2 ... <- Doesn't work

dim $newarray[$i] doesn't also work

...so what else could i do?

any help is welcomed.

thx.

Zetup-EXE

Edited by ZetupEXE
Link to comment
Share on other sites

You could put your arrays inside another array, but this is discouraged. You're probably better off using a multi dimention array.

example:

#include <array.au3>
Local $2DArray[5][10]
For $iRow = 0 To UBound($2DArray) -1
    For $iCollumn = 0 To UBound($2DArray,2) -1
        $2DArray[$iRow][$iCollumn] = "Array" & $iCollumn & " Value" & $iRow
    Next
Next
_ArrayDisplay($2DArray)

The first value of the 5th array would be found using $2DArray[0][4] for instance. And you can add extra collumns, or rows using ReDim.

Link to comment
Share on other sites

  • Moderators

Or you could do it in one line with a single dimension array.

#include <Array.au3> ; For _ArrayDisplay only
Global $s_filename = "FileNameHere"; Could just put this in the fileread call

Global $a_matches = StringRegExp(FileRead($s_filename), '(?i)Menu_ID="(.+?)"', 3)
_ArrayDisplay($a_matches, "Menu IDs")

Basically the same thing that _StringBetween() does, the begging search would be 'Menu_ID="' and the end string would be '"' .

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

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