Jump to content

Two-dimensional array


klsgfx
 Share

Recommended Posts

Hello church,

I have problems with using a two-dimensional array in a for-in-next loop. Would anyone here like to give me a hint?

Local $arrPictures[7][2]

$arrPictures[0][0] = '*.jpg'
$arrPictures[0][1] = ''

$arrPictures[1][0] = '*.nef'
$arrPictures[1][1] = ''

$arrPictures[2][0] = '*.avi'
$arrPictures[2][1] = '*.thm'

$arrPictures[3][0] = '*.mpg'
$arrPictures[3][1] = '*.thm'

$arrPictures[4][0] = '*.3gp'
$arrPictures[4][1] = ''

$arrPictures[5][0] = '*.crw'
$arrPictures[5][1] = '*.thm'

$arrPictures[6][0] = '*.dng'
$arrPictures[6][1] = ''

For $strPattern In $arrPictures
Msgbox(0, 'Show', 'Value: ' & $strPattern[0])
Next

The Msgbox is never shown. Is it because its late night or ..., I do not have a clue.

I am sure, I am doing someting wrong, but what?

Would someone like to help me out?

Thanks and merry Xmas!

Klaus

Link to comment
Share on other sites

I could be wrong, but I think For In Next function is only for object collection or one-dimensional array.

Try this instead:

For $x = 1 To UBound($arrPictures) - 1
    Msgbox(0, 'Show', 'Value: ' & $arrPictures[$x][0])
Next
Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Hello church,

I have problems with using a two-dimensional array in a for-in-next loop. Would anyone here like to give me a hint?

Local $arrPictures[7][2]

$arrPictures[0][0] = '*.jpg'
$arrPictures[0][1] = ''

$arrPictures[1][0] = '*.nef'
$arrPictures[1][1] = ''

$arrPictures[2][0] = '*.avi'
$arrPictures[2][1] = '*.thm'

$arrPictures[3][0] = '*.mpg'
$arrPictures[3][1] = '*.thm'

$arrPictures[4][0] = '*.3gp'
$arrPictures[4][1] = ''

$arrPictures[5][0] = '*.crw'
$arrPictures[5][1] = '*.thm'

$arrPictures[6][0] = '*.dng'
$arrPictures[6][1] = ''

For $strPattern In $arrPictures
Msgbox(0, 'Show', 'Value: ' & $strPattern[0])
Next

The Msgbox is never shown. Is it because its late night or ..., I do not have a clue.

I am sure, I am doing someting wrong, but what?

Would someone like to help me out?

Thanks and merry Xmas!

Klaus

$strPattern will be getting the individual elements of the array, not the rows in the array. Lose the [0] on the end inside the MsgBox call.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

$strPattern will be getting the individual elements of the array, not the rows in the array. Lose the [0] on the end inside the MsgBox call.

Actually that doesn't do anything either.

@klsgfx: I'm pretty sure that Danny35d was right. And looking at your code, it almost seems like you're expecting you could do code like this:

Local $arrPictures[7][2]

$arrPictures[0][0] = '*.jpg'
$arrPictures[0][1] = ''

$arrReference = $arrPictures[0]
MsgBox(0, '', $arrReference[0] & $arrReference[1])

While this would be perfectly acceptible in something like PHP (because $arrPictures[0][0] is an array within an array) it will not work in AutoIt. Multi-dimensional arrays work in an entirely different manner.

Link to comment
Share on other sites

I could be wrong, but I think For In Next function is only for object collection or one-dimensional array.

Try this instead:

For $x = 1 To UBound($arrPictures) - 1
    Msgbox(0, 'Show', 'Value: ' & $arrPictures[$x][0])
Next
Seems like you were right.

$strPattern will be getting the individual elements of the array, not the rows in the array. Lose the [0] on the end inside the MsgBox call.

That did not work, already tried it.

Actually that doesn't do anything either.

@klsgfx: I'm pretty sure that Danny35d was right. And looking at your code, it almost seems like you're expecting you could do code like this:

Local $arrPictures[7][2]

$arrPictures[0][0] = '*.jpg'
$arrPictures[0][1] = ''

$arrReference = $arrPictures[0]
MsgBox(0, '', $arrReference[0] & $arrReference[1])

While this would be perfectly acceptible in something like PHP (because $arrPictures[0][0] is an array within an array) it will not work in AutoIt. Multi-dimensional arrays work in an entirely different manner.

Yes, I earn my living with php. :)

So I will use Danny35d's proposal - lets see how far I will get.

Thanks for all your answers and help.

Hope all will have a peacefull Xmas and a happy new year.

Klaus

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