Jump to content

Getting Subscript used with non-Array variable.


Recommended Posts

I've done this before with no problems (I THOUGHT)

#include <GUIConstants.au3>
#include <ExcelCOM_UDF.au3>  ; Include the Excel collection
Opt("GUIOnEventMode", 1)
Global $oExcel = 1
Global $Counter = 1
Global $array[10]

;Open the Excel file
_ExcelBookOpen(FileOpenDialog("Load Excel Data File", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Data(*.xls)", 1, "RC Test Cases KY set.XLS"), 1, "False")

;Find the last cell
$array = _excelSheetUsedRangeGet($oExcel, 1)
Global $Rows = ($array[3])
Global $Cols = ($array[2])
Global $MasterArray[$Rows][$Cols]

;Load the entire Spreadsheet to the master array
$MasterArray = _ExcelReadSheetToArray($oExcel)

;Load the random child genders
For $Index = 1 To $array[3]
    For $KidIndex = 60 To 69
        $MasterArray[$Index][$KidIndex] = PickGender()
    Next
Next

But now I am getting

C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3 (105) : ==> Subscript used with non-Array variable.: 
 Global $Rows = ($array[3]) 
 Global $Rows = ($array^ ERROR
 ->16:10:43 AutoIT3.exe ended.rc:1

I told it the thing was an array with Global $array[10] so what is Autoit crabbing about?????

Everseeker

Link to comment
Share on other sites

I've done this before with no problems (I THOUGHT)

#include <GUIConstants.au3>
#include <ExcelCOM_UDF.au3>  ; Include the Excel collection
Opt("GUIOnEventMode", 1)
Global $oExcel = 1
Global $Counter = 1
Global $array[10]

;Open the Excel file
_ExcelBookOpen(FileOpenDialog("Load Excel Data File", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Data(*.xls)", 1, "RC Test Cases KY set.XLS"), 1, "False")

;Find the last cell
$array = _excelSheetUsedRangeGet($oExcel, 1)
Global $Rows = ($array[3])
Global $Cols = ($array[2])
Global $MasterArray[$Rows][$Cols]

;Load the entire Spreadsheet to the master array
$MasterArray = _ExcelReadSheetToArray($oExcel)

;Load the random child genders
For $Index = 1 To $array[3]
    For $KidIndex = 60 To 69
        $MasterArray[$Index][$KidIndex] = PickGender()
    Next
Next

But now I am getting

C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3 (105) : ==> Subscript used with non-Array variable.: 
 Global $Rows = ($array[3]) 
 Global $Rows = ($array^ ERROR
 ->16:10:43 AutoIT3.exe ended.rc:1

I told it the thing was an array with Global $array[10] so what is Autoit crabbing about?????

Hi,

Do an "ArrayDisplay" after your $array=[Excel func]line; it is possibly already a 2D array (although I have not used this function myself; it would possibly help you debug it)?

Best, randall

Link to comment
Share on other sites

C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3 (105) : ==> Subscript used with non-Array variable.: 
 Global $Rows = ($array[3]) 
 Global $Rows = ($array^ ERROR
 ->16:10:43 AutoIT3.exe ended.rc:1

I told it the thing was an array with Global $array[10] so what is Autoit crabbing about?????

maby the problem is in your exel version or on autoit version

on 2002 and with old v3.2.4.9 no errors only, Unknown function name

$MasterArray = _ExcelReadSheetToArray($oExcel)

$MasterArray = ^ ERROR (maby i have old udf)

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Hi,

Do an "ArrayDisplay" after your $array=[Excel func]line; it is possibly already a 2D array (although I have not used this function myself; it would possibly help you debug it)?

Best, randall

Ummm... ArrayDisplay?

I tried to use VarDump... no joy

Here's my latest. You can see the versions in use... (Could there be an [issue with/bug in] the new version of ExcelCom_UDF??)

#cs ----------------------------------------------------------------------------
    Title:            RCBulkTest.au3
    AutoIt Version: 3.2.10.0
    Author:         Patrick McCarthy
    Company:        HumanaOne
    
    Script Function:
    Bulk Rate test for Rate Calculator
    
    Script Version:    0.0.3
    Initiated:        01/03/08
    Last Update:    01/10/08
    
    *** ExcelCOM_UDF.au3     Microsoft Excel COM UDF library for AutoIt v3
    *** Current Ver:        1.4
    *** Thanks to SEO aka Locodarwin, DaLiMan, Stanley Lim, MikeOsdx, MRDev, big_daddy, and PsaltyDS
 
 
#ce ----------------------------------------------------------------------------
Opt("GUIOnEventMode", 1)
#include <GUIConstants.au3>     ; Load the standard Constants pack
#include <ExcelCOM_UDF.au3>  ; Include the Microsoft Excel COM UDF library for AutoIt v3

Global $oExcel = 1
Global $Counter = 1
Global $array[10]

;Open the Excel file
_ExcelBookOpen(FileOpenDialog("Load Excel Data File", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Data(*.xls)", 1, "RC Test Cases KY set.XLS"), 1, "False")

;Find the last cell
$array = _excelSheetUsedRangeGet($oExcel, 1)
ConsoleWrite(_VarDump($array))

Global $Rows = ($array[3])
Global $Cols = ($array[2])
Global $MasterArray[$Rows][$Cols]
ConsoleWrite(_VarDump($MasterArray))

;Load the entire Spreadsheet to the master array
$MasterArray = _ExcelReadSheetToArray($oExcel)

;Load the random child genders
For $Index = 1 To $array[3]
    For $KidIndex = 60 To 69
        $MasterArray[$Index][$KidIndex] = PickGender()
    Next
Next

;Data loaded, now hide the Excel spreadsheet
_excelHide($oExcel)
#cs =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
    ;    [Clip]   Launch Rate Calc and process the array
#ce =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

;    Provide summary data
ConsoleWrite(_VarDump($MasterArray))

;    Exit

#cs ----------------------------------------------------------------------------
    Following is the function collection...
#ce ----------------------------------------------------------------------------
Func PickGender()
    If Random(0, 2) <= 1 Then
        Return "M"
    Else
        Return "F"
    EndIf
EndFunc   ;==>PickGender

Func _VarDump(ByRef $vVar, $sIndent = '')
    Select
        Case IsDllStruct($vVar)
            Return 'Struct(' & DllStructGetSize($vVar) & ')'
        Case IsArray($vVar)
            Return 'Array' & @CRLF & _VarDumpArray($vVar, $sIndent)
        Case IsBinary($vVar)
            Return 'Binary(' & BinaryLen($vVar) & ')'
        Case IsBool($vVar)
            Return 'Boolean(' & $vVar & ')'
        Case IsFloat($vVar)
            Return 'Float(' & $vVar & ')'
        Case IsHWnd($vVar)
            Return 'HWnd(' & $vVar & ')'
        Case IsInt($vVar)
            Return 'Integer(' & $vVar & ')'
        Case IsKeyword($vVar)
            Return 'Keyword(' & $vVar & ')'
        Case IsObj($vVar)
            Return 'Object(' & ObjName($vVar) & ')'
        Case IsString($vVar)
            Return 'String(' & StringLen($vVar) & ') ' & $vVar
        Case Else
            Return 'Unknown(' & $vVar & ')'
    EndSelect
EndFunc   ;==>_VarDump

Func _VarDumpArray(ByRef $aArray, $sIndent = '')
    Local $sDump
    Local $sArrayFetch, $sArrayRead, $bDone
    Local $iSubscripts = UBound($aArray, 0)
    Local $aUBounds[$iSubscripts]
    Local $aCounts[$iSubscripts]
    $iSubscripts -= 1
    For $i = 0 To $iSubscripts
        $aUBounds[$i] = UBound($aArray, $i + 1) - 1
        $aCounts[$i] = 0
    Next
    $sIndent &= @TAB
    While 1
        $bDone = True
        $sArrayFetch = ''
        For $i = 0 To $iSubscripts
            $sArrayFetch &= '[' & $aCounts[$i] & ']'
            If $aCounts[$i] < $aUBounds[$i] Then $bDone = False
        Next

        $sArrayRead = Execute('$aArray' & $sArrayFetch)
        If @error Then
            ExitLoop
        Else
            $sDump &= $sIndent & $sArrayFetch & ' => ' & _VarDump($sArrayRead, $sIndent)
            If Not $bDone Then
                $sDump &= @CRLF
            Else
                Return $sDump
            EndIf
        EndIf

        For $i = $iSubscripts To 0 Step - 1
            $aCounts[$i] += 1
            If $aCounts[$i] > $aUBounds[$i] Then
                $aCounts[$i] = 0
            Else
                ExitLoop
            EndIf
        Next
    WEnd
EndFunc   ;==>_VarDumpArray

When I run the script, I get the following output (Oddly, I get nothing from the VarDump function...?)

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams   
 +>10:49:20 Starting AutoIt3Wrapper v.1.9.4
 >Running AU3Check (1.54.10.0)  from:C:\Program Files\AutoIt3
 +>10:49:20 AU3Check ended.rc:0
 >Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3"    
 Integer(0)C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3 (109) : ==> Subscript used with non-Array variable.: 
 Global $Rows = ($array[3]) 
 Global $Rows = ($array^ ERROR
 ->10:49:31 AutoIT3.exe ended.rc:1
 +>10:49:32 AutoIt3Wrapper Finished
 >Exit code: 1  Time: 12.851

Everseeker

Link to comment
Share on other sites

Ummm... ArrayDisplay?

I tried to use VarDump... no joy

Here's my latest. You can see the versions in use... (Could there be an [issue with/bug in] the new version of ExcelCom_UDF??)

#cs ----------------------------------------------------------------------------
    Title:            RCBulkTest.au3
    AutoIt Version: 3.2.10.0
    Author:         Patrick McCarthy
    Company:        HumanaOne
    
    Script Function:
    Bulk Rate test for Rate Calculator
    
    Script Version:    0.0.3
    Initiated:        01/03/08
    Last Update:    01/10/08
    
    *** ExcelCOM_UDF.au3     Microsoft Excel COM UDF library for AutoIt v3
    *** Current Ver:        1.4
    *** Thanks to SEO aka Locodarwin, DaLiMan, Stanley Lim, MikeOsdx, MRDev, big_daddy, and PsaltyDS
 
 
#ce ----------------------------------------------------------------------------
Opt("GUIOnEventMode", 1)
#include <GUIConstants.au3>     ; Load the standard Constants pack
#include <ExcelCOM_UDF.au3>  ; Include the Microsoft Excel COM UDF library for AutoIt v3

Global $oExcel = 1
Global $Counter = 1
Global $array[10]

;Open the Excel file
_ExcelBookOpen(FileOpenDialog("Load Excel Data File", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Data(*.xls)", 1, "RC Test Cases KY set.XLS"), 1, "False")

;Find the last cell
$array = _excelSheetUsedRangeGet($oExcel, 1)
ConsoleWrite(_VarDump($array))

Global $Rows = ($array[3])
Global $Cols = ($array[2])
Global $MasterArray[$Rows][$Cols]
ConsoleWrite(_VarDump($MasterArray))

;Load the entire Spreadsheet to the master array
$MasterArray = _ExcelReadSheetToArray($oExcel)

;Load the random child genders
For $Index = 1 To $array[3]
    For $KidIndex = 60 To 69
        $MasterArray[$Index][$KidIndex] = PickGender()
    Next
Next

;Data loaded, now hide the Excel spreadsheet
_excelHide($oExcel)
#cs =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
=+=+=+=+=+=+=+=+=+=+
    ;    [Clip]   Launch Rate Calc and process the array
#ce =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
=+=+=+=+=+=+=+=+=+=+=+=+

;    Provide summary data
ConsoleWrite(_VarDump($MasterArray))

;    Exit

#cs ----------------------------------------------------------------------------
    Following is the function collection...
#ce ----------------------------------------------------------------------------
Func PickGender()
    If Random(0, 2) <= 1 Then
        Return "M"
    Else
        Return "F"
    EndIf
EndFunc   ;==>PickGender

Func _VarDump(ByRef $vVar, $sIndent = '')
    Select
        Case IsDllStruct($vVar)
            Return 'Struct(' & DllStructGetSize($vVar) & ')'
        Case IsArray($vVar)
            Return 'Array' & @CRLF & _VarDumpArray($vVar, $sIndent)
        Case IsBinary($vVar)
            Return 'Binary(' & BinaryLen($vVar) & ')'
        Case IsBool($vVar)
            Return 'Boolean(' & $vVar & ')'
        Case IsFloat($vVar)
            Return 'Float(' & $vVar & ')'
        Case IsHWnd($vVar)
            Return 'HWnd(' & $vVar & ')'
        Case IsInt($vVar)
            Return 'Integer(' & $vVar & ')'
        Case IsKeyword($vVar)
            Return 'Keyword(' & $vVar & ')'
        Case IsObj($vVar)
            Return 'Object(' & ObjName($vVar) & ')'
        Case IsString($vVar)
            Return 'String(' & StringLen($vVar) & ') ' & $vVar
        Case Else
            Return 'Unknown(' & $vVar & ')'
    EndSelect
EndFunc   ;==>_VarDump

Func _VarDumpArray(ByRef $aArray, $sIndent = '')
    Local $sDump
    Local $sArrayFetch, $sArrayRead, $bDone
    Local $iSubscripts = UBound($aArray, 0)
    Local $aUBounds[$iSubscripts]
    Local $aCounts[$iSubscripts]
    $iSubscripts -= 1
    For $i = 0 To $iSubscripts
        $aUBounds[$i] = UBound($aArray, $i + 1) - 1
        $aCounts[$i] = 0
    Next
    $sIndent &= @TAB
    While 1
        $bDone = True
        $sArrayFetch = ''
        For $i = 0 To $iSubscripts
            $sArrayFetch &= '[' & $aCounts[$i] & ']'
            If $aCounts[$i] < $aUBounds[$i] Then $bDone = False
        Next

        $sArrayRead = Execute('$aArray' & $sArrayFetch)
        If @error Then
            ExitLoop
        Else
            $sDump &= $sIndent & $sArrayFetch & ' => ' & _VarDump($sArrayRead, $sIndent)
            If Not $bDone Then
                $sDump &= @CRLF
            Else
                Return $sDump
            EndIf
        EndIf

        For $i = $iSubscripts To 0 Step - 1
            $aCounts[$i] += 1
            If $aCounts[$i] > $aUBounds[$i] Then
                $aCounts[$i] = 0
            Else
                ExitLoop
            EndIf
        Next
    WEnd
EndFunc   ;==>_VarDumpArray

When I run the script, I get the following output (Oddly, I get nothing from the VarDump function...?)

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams   
  +>10:49:20 Starting AutoIt3Wrapper v.1.9.4
  >Running AU3Check (1.54.10.0)  from:C:\Program Files\AutoIt3
  +>10:49:20 AU3Check ended.rc:0
  >Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3"   
  Integer(0)C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3 (109) : ==> Subscript used with non-Array variable.: 
  Global $Rows = ($array[3]) 
  Global $Rows = ($array^ ERROR
  ->10:49:31 AutoIT3.exe ended.rc:1
  +>10:49:32 AutoIt3Wrapper Finished
  >Exit code: 1 Time: 12.851
WOW! Just spotted the Integer(0)

So, there IS a bug .... Copying this to the correct thread

Everseeker

Link to comment
Share on other sites

I've done this before with no problems (I THOUGHT)

;Open the Excel file

_ExcelBookOpen(FileOpenDialog("Load Excel Data File", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Data(*.xls)", 1, "RC Test Cases KY set.XLS"), 1, "False")

;Find the last cell

$array = _excelSheetUsedRangeGet($oExcel, 1)

_ExcelBookOpen() returns an object identifier. You are simply ignoring it and then you're using an undefined Variable $oExcel with _excelSheetUsedRangeGet(). That's not going to work.

Try this:

Local $oExcel = _ExcelBookOpen(....

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

_ExcelBookOpen() returns an object identifier. You are simply ignoring it and then you're using an undefined Variable $oExcel with _excelSheetUsedRangeGet(). That's not going to work.

Try this:

Local $oExcel = _ExcelBookOpen(....

Cheers

Kurt

Oh my... wonder why that USED to work... It's obviously an error now that you mentioned it....

Thanks

Everseeker

Link to comment
Share on other sites

Oh my... wonder why that USED to work... It's obviously an error now that you mentioned it....

Thanks

Ummm... Got about an inch further... now the problem is here

Global $Rows = ($array[3])
Global $Cols = ($array[2])
$Rows = $Rows + 2
$Cols = $Cols + 12

Global $MasterArray[$Rows][$Cols]
ConsoleWrite("Rows=" & $Rows & ", Columns=" & $Cols & ". " & @CRLF)

;Load the entire Spreadsheet to the master array
$MasterArray = _ExcelReadSheetToArray($oExcel)
ConsoleWrite(_VarDump($MasterArray) & @CRLF)
;Load the random child genders
For $Index = 1 To $Rows
    For $KidIndex = 61 To 69
        ConsoleWrite(" Index[Row]=" & $Index & ", KidIndex[Column]=" & $KidIndex & ".  " & @CRLF)
        $MasterArray[$Index][$KidIndex] = PickGender()
    Next
Next

looks plain... But, the end of the output to the console shows an error:

Array
     [0] => String(4) BH52
     [1] => String(6) R52C60
     [2] => Integer(60)
     [3] => Integer(52)
 Rows=54, Columns=72. 
 Array
     [0][0] => Integer(52)
     [0][1] => Integer(60)
     [0][2] => String(0) 
     [0][3] => String(0) 
     [0][4] => String(0)
  ...(clipped)
     [52][59] => Float(67.77)
     [52][60] => Float(67.77)
  Index[Row]=1, KidIndex[Column]=61.  
 C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3 (123) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: 
 $MasterArray[$Index][$KidIndex] = PickGender() 
 ^ ERROR
 -

I THINK I am asking it to do the following:

$MasterArray[1][61]="M" which should work... (I increased the Rows by 2 and the columns by 12 to allow for this)

Unless... Does outputting the array to $masterindex... Cause the dimensions to shrink?

If so, how do I overcome that?

Edited by everseeker

Everseeker

Link to comment
Share on other sites

Ummm... Got about an inch further... now the problem is here

Global $Rows = ($array[3])
Global $Cols = ($array[2])
$Rows = $Rows + 2
$Cols = $Cols + 12

Global $MasterArray[$Rows][$Cols]
ConsoleWrite("Rows=" & $Rows & ", Columns=" & $Cols & ". " & @CRLF)

;Load the entire Spreadsheet to the master array
$MasterArray = _ExcelReadSheetToArray($oExcel)
ConsoleWrite(_VarDump($MasterArray) & @CRLF)
;Load the random child genders
For $Index = 1 To $Rows
    For $KidIndex = 61 To 69
        ConsoleWrite(" Index[Row]=" & $Index & ", KidIndex[Column]=" & $KidIndex & ".  " & @CRLF)
        $MasterArray[$Index][$KidIndex] = PickGender()
    Next
Next

looks plain... But, the end of the output to the console shows an error:

Array
      [0] => String(4) BH52
      [1] => String(6) R52C60
      [2] => Integer(60)
      [3] => Integer(52)
  Rows=54, Columns=72. 
  Array
      [0][0] => Integer(52)
      [0][1] => Integer(60)
      [0][2] => String(0) 
      [0][3] => String(0) 
      [0][4] => String(0)
   ...(clipped)
      [52][59] => Float(67.77)
      [52][60] => Float(67.77)
   Index[Row]=1, KidIndex[Column]=61.  
  C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3 (123) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: 
  $MasterArray[$Index][$KidIndex] = PickGender() 
  ^ ERROR
  -

I THINK I am asking it to do the following:

$MasterArray[1][61]="M" which should work... (I increased the Rows by 2 and the columns by 12 to allow for this)

Unless... Does outputting the array to $masterindex... Cause the dimensions to shrink?

If so, how do I overcome that?

Edited by everseeker

Everseeker

Link to comment
Share on other sites

<Moving this discussion to ExcelCom_Udf thread... It may be an issue with the "new" code there>

It doesn't matter what size you make the array beforehand. The array returned by _ExcelReadSheetToArray() overwrites it. If you look at the header for that function you will see the following note:

Returned array has row count in [0][0] and column count in [0][1].

Put this in for a debug run:

;Load the entire Spreadsheet to the master array
$MasterArray = _ExcelReadSheetToArray($oExcel)
ConsoleWrite("Debug: Returned array last element is $MasterArray[" & $MasterArray[0][0] & "][" & $MasterArray[0][1] & "]" & @LF)
;Load the random child genders
For $Index = 1 To $MasterArray[0][0]
    If $MasterArray[0][1] >= 61 Then
        For $KidIndex = 61 To $MasterArray[0][1]
            ConsoleWrite(" Index[Row]=" & $Index & ", KidIndex[Column]=" & $KidIndex & ".  " & @CRLF)
            $MasterArray[$Index][$KidIndex] = PickGender()
        Next
    EndIf
Next

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

It doesn't matter what size you make the array beforehand. The array returned by _ExcelReadSheetToArray() overwrites it.

:)

Ummm... OK. (Although I understood the note to be informative... telling the user what range in his array was now containing the array data from excel.)

Since you're re-sizing the array, how shall I go about doing what I need to do?

(Pull data from excel table, add column data, use data in an external program, scrape results into additional columns, do another program, scrape results into additional rows, and then place the resulting array BACK into the Excel book, as a new sheet)

If you recall, my old method was to pull a row into an array, then to copy that 1d array to master array, then get another row & repeat...

So you made the 2d mod... to save time.

Do I STILL need to do the copy?

if so, will the following work?

Global $Masterexcel[10][10]

Global $MasterArray[20][20]

pull Excel range into $MasterExcel

$MasterArray=Masterexcel

or

after getting the data into $MasterExcel, can I do a

ReDim $MasterExcel[20][20] ? Or would that wipe the data?

Everseeker

Link to comment
Share on other sites

Ummm... OK. (Although I understood the note to be informative... telling the user what range in his array was now containing the array data from excel.)

Since you're re-sizing the array, how shall I go about doing what I need to do?

(Pull data from excel table, add column data, use data in an external program, scrape results into additional columns, do another program, scrape results into additional rows, and then place the resulting array BACK into the Excel book, as a new sheet)

If you recall, my old method was to pull a row into an array, then to copy that 1d array to master array, then get another row & repeat...

So you made the 2d mod... to save time.

Do I STILL need to do the copy?

if so, will the following work?

Global $Masterexcel[10][10]

Global $MasterArray[20][20]

pull Excel range into $MasterExcel

$MasterArray=Masterexcel

or

after getting the data into $MasterExcel, can I do a

ReDim $MasterExcel[20][20] ? Or would that wipe the data?

There is nothing about this that is specific to ExcelCOM_UDF, or these functions. Every function, native or UDF, that returns an array will overwrite the previous array if that's the assignment you make in the code. That was your choice in your code. If you must have an array of a certain size and structure then the process would be:

Global $SomeVar
Global $avYourArray[20][20]
$SomeVar = SomeFunction()
; Do something to put data from $SomeVar into $avYourArray...

ReDim will work, providing you don't change the number of subscripts (dimensions):

Global $SomeVar
Global $avYourArray[20][20]
$SomeVar = SomeFunction()
If (@error = 0) And (Ubound($SomeVar, 0) = 2) Then 
     ReDim $SomeVar[20][20]
     $avYourArray = $SomeVar
EndIf

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

There is nothing about this that is specific to ExcelCOM_UDF, or these functions. Every function, native or UDF, that returns an array will overwrite the previous array if that's the assignment you make in the code. That was your choice in your code. If you must have an array of a certain size and structure then the process would be:

Global $SomeVar
 Global $avYourArray[20][20]
 $SomeVar = SomeFunction()
; Do something to put data from $SomeVar into $avYourArray...

ReDim will work, providing you don't change the number of subscripts (dimensions):

Global $SomeVar
 Global $avYourArray[20][20]
 $SomeVar = SomeFunction()
 If (@error = 0) And (Ubound($SomeVar, 0) = 2) Then 
      ReDim $SomeVar[20][20]
      $avYourArray = $SomeVar
 EndIf

:)

Can I do this? (to save the time taken by the copy step)

Global $avYourArray
$avYourArray = SomeFunction()
 If (@error = 0) And (Ubound($avYourArray, 0) = 2) Then 
      ReDim $avYourArray[20][20]
EndIf

Everseeker

Link to comment
Share on other sites

Can I do this? (to save the time taken by the copy step)

Global $avYourArray
$avYourArray = SomeFunction()
 If (@error = 0) And (Ubound($avYourArray, 0) = 2) Then 
      ReDim $avYourArray[20][20]
EndIf
Certainly. But why ask? You'll learn/remember more if you just test it and see.

Every big script I write (tend to be 1500 to 2000 lines), is accompanied by about ten little Test.au3 scripts of about five lines each to make sure parts work the way I thought they did. That's where the learning happens.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Certainly. But why ask? You'll learn/remember more if you just test it and see.

Every big script I write (tend to be 1500 to 2000 lines), is accompanied by about ten little Test.au3 scripts of about five lines each to make sure parts work the way I thought they did. That's where the learning happens.

:)

point taken

(and yup, it worked... after I asked, I decided to try...)

next up,

I am having issues with user controls... but that'll wait till I've tried to figure it out myself...

:P

Everseeker

Link to comment
Share on other sites

next up,

I am having issues with user controls... but that'll wait till I've tried to figure it out myself...

:P

Ahh... a touch of learning and a modicum of wisdom have come to this student.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...