cwoolsey

Basic Array Error working with Excel! Please help!

5 posts in this topic

I am a super noob at AutoIt so bare with me.

Here is my code:

      ;Define the Variables entered in Previous Table
      $ItemOut = GUICtrlRead($ItemOutID)
      $NumItemOut = GUICtrlRead($NumItemOutId)
      $Who = GUICtrlRead($WhoId)
      $Where = GUICtrlRead($WhereID)

      ;Set the filepath to the excel documents
      $fPath ="P:\IT_Interns\Projects\Inventory Project\Inventory.xlsx"
      ;Open a specific Excel window
      $app = _Excel_Open()
      ;Wait till that window has opened and is active
      WinWaitActive("Excel")
      ;Open the workbook we are using with the given filepath
      $Excel = _Excel_BookOpen( $app, $fPath, Default, Default, True)

      Global $array = _Excel_RangeFind($Excel, $ItemOut, Default, Default, $xlWhole)
      $arrayData = $array[2]

The problem is with the last line of code and reads: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

How is this possible?

The array is created and assigned to _Excel_RangeFind function which returns 6 values, I am trying to only obtain the 3rd value which is the address of the specific cell, so $array[2] should access the third value in the array; but it throws the error! I ran _ArrayDisplay and it runs fine showing the full 6 values so I know the array Range Find did work and input the values.

 

 

Share this post


Link to post
Share on other sites



I would look at what _Excel_RangeFind returns when it errors, because it probably is.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

cwoolsley,

The function returns a 2D array thus your subscript error.  Try this

$arrayData = $array[2][3] ; to get value of the cell

kylomas

edit: Welcome to the forum.  Please use the code tags when posting code.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thank you so much for the responses! That was exactly it I cannot believe I missed that in the AutoIt Help menu. The location of what I was looking for was in $array[0][2], I have no idea why they input all of the data within the 0th 1st part of the array, they should just put it within a 1D array but nonetheless thank you! Now I just need to find out how to parse through the data to get the next cell over. If it returns A2 I need it to receive the data within B2 cell. I'll post about that on a separate post though!

Share this post


Link to post
Share on other sites

If you always need the content of the cell one column to the right then I would use:

$vResult = $oWorkbook.Range($ItemOut).Offset(0, 1).Value

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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