Jump to content

Excel and an Array Subscript Error


Recommended Posts

Hello, 

I am making a simple script to read a range of cells in a spread sheet and return the first cell's value. 

Global $sExcelReferencePath = "\refDoc.xls"

Local $oExcel = _Excel_Open()

Local $oWorkBook = _Excel_BookOpen ($oExcel, @ScriptDir&$sExcelReferencePath)

Local $iRowVal = 2

Local $propArray[9] = _Excel_RangeRead ( $oWorkbook , "Sheet1", "A2:I2", 1 )

If isArray ($propArray) = 1 Then
   ConsoleWrite ("yay")
Else
   ConsoleWrite ("Boo")
EndIf

ConsoleWrite ($propArray[0])

When I run this script , it finds the values and confirms that $propArray is an array but when I try to call $propArray[0] I get back "Array variable has incorrect number of subscripts or subscript dimension range exceeded"

Any advice regarding this would be thoroughly appreciated. 

Link to comment
Share on other sites

I figured out my error. 

When collecting data from an Excel sheet , even if just a single row, it requires row and column values to designate what portion of the array is to be used/displayed.

So $propArray is actually "$propArray[0][9]" and to reference it is the same. Hope this helps some future novice from making the same error I did :)

Link to comment
Share on other sites

Hi. You don't need to define the array size like Local $propArray[9]= just use Local $propArray=

 

Saludos

 

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