Jump to content

assigning values to a 2 dim array


Recommended Posts

Hi real programmers!

Behold a text file:

123,654,789,098

453,765,982,180

765,432,987,222

I started with FileReadLine to $tempString

After that i used StringSplit and i populated $tempArray like this:

$tempArray[0]=4

$tempArray[1]=123

$tempArray[2]=654

$tempArray[3]=789

$tempArray[4]=098

Now i want to populate $finalArray, which is TWO-dimensional as follows:

$finalArray[$ruleNumber][1] = $tempArray[1]

$finalArray[$ruleNumber][2] = $tempArray[2]

$finalArray[$ruleNumber][3] = $tempArray[3]

$finalArray[$ruleNumber][4] = $tempArray[4]

But that doesn't work of course. How can i do that?

Bye, bye!

Find the job of your life and you will never have to work again!

Link to comment
Share on other sites

  • Moderators

Hi real programmers!

Behold a text file:

123,654,789,098

453,765,982,180

765,432,987,222

I started with FileReadLine to $tempString

After that i used StringSplit and i populated $tempArray like this:

$tempArray[0]=4

$tempArray[1]=123

$tempArray[2]=654

$tempArray[3]=789

$tempArray[4]=098

Now i want to populate $finalArray, which is TWO-dimensional as follows:

$finalArray[$ruleNumber][1] = $tempArray[1]

$finalArray[$ruleNumber][2] = $tempArray[2]

$finalArray[$ruleNumber][3] = $tempArray[3]

$finalArray[$ruleNumber][4] = $tempArray[4]

But that doesn't work of course. How can i do that?

Bye, bye!

Find the job of your life and you will never have to work again!

Have an actual script to go off of so we aren't guessing what $ruleNumber is?

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

  • Moderators

Again, without your script, I have no idea what your really trying to accomplish... I guess I'll chase the tail one time:

Local $aArray = StringSplit('123,654,789,098', ',')
Local $tArray[5][5]
For $i = 1 To UBound($aArray) - 1
    $tArray[$i][1] = $aArray[$i]
    $tArray[$i][2] = $aArray[$i]
    $tArray[$i][3] = $aArray[$i]
    $tArray[$i][4] = $aArray[$i]
Next

For $x = 1 To UBound($tArray) - 1
    MsgBox(0, 'Example', $tArray[$x][$x])
Next

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

  • Moderators

This made more sense:

#include <file.au3>
Local $FilePath = @DesktopDir & '\2Darray.txt'
Local $nArray = ''
_FileReadToArray($FilePath, $nArray)
Local $tArray[UBound($nArray)][5]

For $i = 1 To UBound($nArray) - 1
    Local $aArray = StringSplit($nArray[$i], ',')
    For $x = 1 To UBound($aArray) - 1
        $tArray[$i][$x] = $aArray[$x]
    Next
Next

For $x = 1 To UBound($tArray) - 1
    For $i = 1 To 4
        MsgBox(0, 'Test', $tArray[$x][$i])
    Next
Next

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