Jump to content

Basic Array Error working with Excel! Please help!


Recommended Posts

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.

 

 

Link to comment
Share on other sites

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

Link to comment
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!

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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