Jump to content

Noob Question About Arrays


Recommended Posts

#Include <File.au3>
#include <array.au3>

Local $File = "c:\test\myfile.txt"
Dim $Array[2][2]=[["a","b"],["c","d"]]
_ArrayDisplay($Array)
_FileWriteFromArray($File, $Array)

Exit

Displays the array OK, but yields:

C:\Program Files\AutoIt3\Include\File.au3 (279) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If FileWrite($hFile, $a_Array[$x] & @CRLF) = 0 Then
If FileWrite($hFile, ^ ERROR

I've tried everything I can think of, spent hours searching for a clue.

Can someone please lend me a clue? Is there a tutorial around on how to properly initialize arrays? Can they be sized larger than needed? Or smaller? I'm having trouble parsing this line about initializing arrays: "You can specify fewer elements in the initializer than declared, but not more." I don't get 'declared' versus 'specify'.

Thanks,

--97T--

Link to comment
Share on other sites

  • Moderators

You've declared a 2 dimension array here:

Dim $Array[2][2]

^^ But that's not even the Array value ($Array is not $a_Array) and it's 2 Dimension versus the 1 dimension you're using below.

But you're using it as a 1 Dimension Array here:

If FileWrite($hFile, $a_Array[$x] & @CRLF) = 0 Then

Might try:

If FileWrite($hFile, $a_Array[$x][0] & @CRLF) = 0 Then

Or

If FileWrite($hFile, $a_Array[$x][1] & @CRLF) = 0 Then

Depending on what 2nd dimension you actually want to be using there (if that's even the variable you think you should be using).

Edited by SmOke_N
Clarity

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

You've declared a 2 dimension array here:

Dim $Array[2][2]

^^ But that's not even the Array value ($Array is not $a_Array) and it's 2 Dimension versus the 1 dimension you're using below.

But you're using it as a 1 Dimension Array here:

If FileWrite($hFile, $a_Array[$x] & @CRLF) = 0 Then

Might try:

If FileWrite($hFile, $a_Array[$x][0] & @CRLF) = 0 Then

Or

If FileWrite($hFile, $a_Array[$x][1] & @CRLF) = 0 Then

Depending on what 2nd dimension you actually want to be using there (if that's even the variable you think you should be using).

Thanks, I took a look at the UDF and realized it is only designed to write one-dimensional arrays. I shouldn't stay up so late!

--97T--

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