Jump to content

Recommended Posts

Posted

What table looks like 

image.png.e1d6d3ff05f6cdd66c795588c7c93c17.png

What html looks like 

image.png.f600adea13259b4750bd6f58b750c642.png

So I use a for loop to search this table for "Not Allocated" 

$colLinks = _IEGetObjById($oIE, "ctl00_MPH_PanelListing_ctlInvoiceListing")
$TDs = _IETagNameGetCollection($colLinks, "td")
For $oLink in $TDs
    If String($oLink.textContent) = "Not Allocated" Then
       ConsoleWrite(@CRLF & "Found Not Allocated ")
       _IEAction($oLink, "click")
        ExitLoop
    EndIf
 Next

However I would then like to be able to access the adjacent TD cells. (such as the Customer Name/ Ledger Reference/Matter Number etc.

How would I do this whilst ensuring I'm not pulling a TD cell from a difference row? 

Posted

So my plan was to loop through the table collections and then search using string in string

_IETableGetCollection($oIE)
$iNumTables = @extended
For $i = 0 To $iNumTables - 1
    $oTable = _IETableGetCollection($oIE, $i)
    $aTableData = _IETableWriteToArray($oTable)
    if StringInStr($aTableData[0][0], "Not Allocated") Then
       MsgBox(64, "Debug", "Found the table with Not Allocated in", 2)
       $aTableData[0][0] = $NotAllocatedTableCell
       _ArrayDisplay($aTableData, "Table #" & $i)
       MsgBox(64, "Debug", "$NotAllocatedTableCell equals: " & $NotAllocatedTableCell)
       MsgBox(64, "Debug", "$NotAllocatedTableCell equals: " & $aTableData[0][0])
       endif
Next

However as some tables seem to contain nothing it then fails with

(239) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

So I'm wondering if there is a way to test that $aTableData[0][0] is a valid array? 

Posted

You can use the Ubound command, to check how many items are in the array.

You can use IsArray to determine if the variable is an array.

And whenever you call the functions, which return an array, you can check if @error has been set or not. 

Some of my script sourcecode

Posted

Does anyone know why I get 

 

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Despite using the Isarray function and wrapping in an if statement?

_IETableGetCollection($oIE)
$iNumTables = @extended
For $i = 0 To $iNumTables - 1
    $oTable = _IETableGetCollection($oIE, $i)
    $aTableData = _IETableWriteToArray($oTable)
    If IsArray($aTableData) Then
    if StringInStr($aTableData, "Not Allocated") Then
       If @Error then
          ConsoleWrite(@CRLF & "@Error triggered: $aTableData is not an array.")
          EndIf
       MsgBox(64, "Debug", "Found the table with Not Allocated in", 2)

       $aTableData[0][0] = $NotAllocatedTableCell

       MsgBox(64, "Debug", "$NotAllocatedTableCell equals: " & $NotAllocatedTableCell)
       MsgBox(64, "Debug", "$NotAllocatedTableCell equals: " & $aTableData[0][0])
    endif

 EndIf

Next

 

Posted (edited)

When i'm prototyping my scripts, i usually use _ArrayDisplay to see what the array is containing.

$oTable = _IETableGetCollection($oIE, $i)
    _ArrayDisplay($oTable)
    $aTableData = _IETableWriteToArray($oTable)
    _ArrayDisplay($aTableData)

You may notice, that, if one array contain nothing, for e.g $aTableData[0][0] will be set to 0

The other way, which i found useful, is to check if $aTableData is -1

Here is an example:

#include <Misc.au3>
Dim $aFont[8]    ;Font array definition
$aFont = _ChooseFont($aFont[2], $aFont[3], $aFont[5], $aFont[4], 0, 0, 0)

ConsoleWrite($aFont & @CRLF)

if $aFont=-1 then
    ConsoleWrite ("not an array" & @crlf)
EndIf

If you choose a valid Font, then -1 and "not an array" will not appear in the console.

But if you click on cancel, then you will see both messages.

Edited by Dan_555

Some of my script sourcecode

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
×
×
  • Create New...