Jump to content

dynamic arrays


Recommended Posts

Here is an example that shows how you could do:

#Include <File.au3>
#Include <Array.au3>

$servers = FileOpenDialog("Open txt files", @DesktopDir & "", "Text File (*.txt)", 1 )
If @error Then Exit

Global $loadArray, $Data
Dim $dataArray[1][2]
_FileReadToArray($servers, $loadArray)
;_ArrayDisplay($loadArray)
;_ArrayDisplay($dataArray)
For $i = 1 to Ubound($loadArray)-1
    $Data = StringSplit($loadArray[$i], ", ",1)

    ReDim $dataArray[$i+1][2]
    $dataArray[$i][0] = $Data[1]
    $dataArray[$i][1] = $Data[2]
    $dataArray[0][0] = $i
Next
_ArrayDisplay($dataArray)

Regards

Edited by newbiescripter
Link to comment
Share on other sites

i'm getting an error when i run your script. it says:

line 17:

$dataArray[$i][1]=$Data[2]

Array variable has incorrect number of subscripts or subscript dimension range exceeded.

Edited by dwaynek
Link to comment
Share on other sites

i'm getting an error when i run your script. it says:

line 17:

$dataArray[$i][1]=$Data[2]

Array variable has incorrect number of subscripts or subscript dimension range exceeded.

The problem is blank or mis-formatted lines will not produce the expected StringSplit() array, so some error checking is required. Try changing this section:
Dim $dataArray[1][2] = [[0, ""]]
_FileReadToArray($servers, $loadArray)
For $i = 1 To UBound($loadArray) - 1
    If StringStripWS($loadArray[$i], 8) <> "" Then
        $Data = StringSplit($loadArray[$i], ", ", 1)
        If UBound($Data) = 3 Then
            ReDim $dataArray[UBound($dataArray) + 1][2]
            $dataArray[0] += 1
            $dataArray[$dataArray[0]][0] = $Data[1]
            $dataArray[$dataArray[0]][1] = $Data[2]
        EndIf
    EndIf
Next

:P

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

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