Jump to content

[Solved] Excel - range error if check against wrong type ?


Myicq
 Share

Recommended Posts

Discovered a strange thing today with Excel. Maybe it's just me doing something wrong.

Here's the situation: Excel sheet containing 18 columns by 1700 rows.

For this example, column no. 12 ("M") contains a number. Column 13 ("N") has a number or a text.

I can open the book just fine.

Now I can try:

$a = _Excel_RangeRead($e, 1, "A1:R1700", 1)
for $i = 1 to 1700
    if $a[$i][13] = "XXX" then
        ConsoleWrite("found at " & $i & @LF)
    EndIf
Next

This will work fine, and list all lines containing "XXX".

If I change only the 13:

$a = _Excel_RangeRead($e, 1, "A1:R1700", 1)
for $i = 1 to 1700
    if $a[$i][12] = "XXX" then
        ConsoleWrite("found at " & $i & @LF)
    EndIf
Next

I get an error about the array.

"file.au3" (30) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
if $a[$i][12] = "XXX" then
if ^ ERROR

But I KNOW that the array is correct size, I am only reading a different column. Changing 12 to 11, another mixed column, and it will work.

What did I miss - why can't I check a number against "XXX" string ? After all I know, it should just fail, like "if 3= 'XXX' then ..."

 

EDIT: well, I guess it's real embaressing: I think I messed up the 0 or 1-based array.  :

This topic may be deleted if admins see fit.. otherwise marked solved.

Edited by Myicq

I am just a hobby programmer, and nothing great to publish right now.

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

×
×
  • Create New...