SorryButImaNewbie

[SOLVED] Another "Array variable has incorrect number of subscripts or subscript dimension range exceeded"

22 posts in this topic

#1 ·  Posted (edited)

Hello!

Sorry for the weekly simpleton question, but:

I tried to make a part of my code be able to handle arrays of any size (Before, I used a fixed array size of 4, which is far from ideal, I just wanted it to run)

I szccesfully read the array size, ReDim it and I thought that I can easly read the values I need, but the 5. version of my code is giving me the same error. I'm not sure, how should I use variabels as "array subscripts" (I mean: $Array[!This for example!][!Or this!])

I wrote the following abomination, Its job would be to read through an array of running/open excel instances and find the one with a .xls extension. Then read its filepath and name  so I can make a copy of it a bit down on the line (BTW Anyother insight if you think I'm doing something wrong or not idealy is welcome!) 

Local $aWorkBooks = _Excel_BookList()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookList Example 2", "Error listing Workbooks." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($aWorkBooks, "Excel UDF: _Excel_BookList Example 2 - List of workbooks of all instances")

;CONSTRUCTION-----------------------------------
;$aWorkBooks array méretezés
If IsArray($aWorkBooks) Then
    ReDim $aWorkBooks[UBound($aWorkBooks)]
    ;MsgBox($MB_SYSTEMMODAL, "Értesítás", "Cucc:" & UBound($aWorkBooks) & "")
    Local $ArrayElement = UBound($aWorkBooks)
    Do
        Local $Int = Int(0)
        ;MsgBox($MB_SYSTEMMODAL, "Értesítés", "Cucc: " & $ArrayElement &" Int: " & $Int &"")
        Local $Array = $aWorkBooks[Int($Int)][1]
        Local $xls = StringRegExp(String($Array), ".xls")
        $Int = Int($Int + 1)
    Until $xls = 1
    $ExcelName = $aWorkBooks[$Int][1]
    $ExcelPath = $aWorkBooks[$Int][2]
Else
    MsgBox($MB_SYSTEMMODAL, "Excel Array Hiba", "Hiba a formázandó excel felismerése közben.")
    Exit
EndIf

Consol Error:

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

Local $Array = $aWorkBooks[Int($Int)][1]
Local $Array = ^ ERROR

I try to use an increasing variable to read the array until its find the .xls extension, the values of $Int is okey according to the message boxes

Thanks for the help, wise users of this forum!

Edit:

You find the solution to this problem in the thread below, also the problem developed into an other one, _Excel_SheetList UDF returned with a "funny array" with numbers (see the pic around comment 5-8) the solution was to disable excel addons: Analysis ToolPak and Solver, not sure which one did the trick at the end. Also in this thread you can find a "bug fix" for _Excel_SheetList , in the current version, _Excel_SheetList gave 0 return to every error, master water posted a fix to that (you have to change a 0 value to @error).

Best of luck!

Edited by SorryButImaNewbie
Because the problem blossomd in to a new one, I edit this so others with similar problems may benefit

Share this post


Link to post
Share on other sites



You ReDim a 2D array to a 1D array with this statement

ReDim $aWorkBooks[UBound($aWorkBooks)]

Drop this statement as I do not see any need for it in your script.


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

#3 ·  Posted (edited)

Ohhh, sounds logical, since I only "read in" the array once, I only need to know its size... And yes, its not a 1D array as I display it and can clearly see...

Thank you master water, I also moved the $int = 0 out from the loop, so its value doesnt jump on 1 to 0 making an infinite loop :D (thats help to)

My code right now:

Local $aWorkBooks = _Excel_BookList()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookList Example 2", "Error listing Workbooks." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($aWorkBooks, "Excel UDF: _Excel_BookList Example 2 - List of workbooks of all instances")

;CONSTRUCTION-----------------------------------
;$aWorkBooks array méretezés
If IsArray($aWorkBooks) Then
    ;ReDim $aWorkBooks[UBound($aWorkBooks)]
    ;MsgBox($MB_SYSTEMMODAL, "Értesítás", "Cucc:" & UBound($aWorkBooks) & "")
    Local $ArrayElement = UBound($aWorkBooks)
    Local $Int = Int(0)
    Do
        ;MsgBox($MB_SYSTEMMODAL, "Értesítés", "Cucc: " & $ArrayElement &" Int: " & $Int &"")
        Local $Array = $aWorkBooks[Int($Int)][1]
        Local $xls = StringRegExp(String($Array), ".xls")
        $Int = $Int + 1
        If $xls = 1 Then
            Global $ExcelName = $aWorkBooks[Int($Int)][1]
            Global $ExcelPath = $aWorkBooks[Int($Int)][2]
        EndIf
    Until $xls = 1
Else
    MsgBox($MB_SYSTEMMODAL, "Excel Array Hiba", "Hiba a formázandó excel felismerése közben.")
    Exit
EndIf
;_Excel_SheetCopyMove
;----------------------------------------------

$ExcelObject = _Excel_BookAttach($ExcelName, "filename")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookAttach Example 2", "Error attaching to '" & $ExcelObject & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

$ExcelSheetListArray = _Excel_SheetList($ExcelObject)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetList Example 1", "Error listing Worksheets." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;_ArrayDisplay($ExcelSheetListArray, "Excel UDF: _Excel_SheetList Example 1")
$ExcelSheetListArrayMaxIndex = _ArrayMaxIndex($ExcelSheetListArray)

Local $oCopiedSheet = _Excel_SheetCopyMove($ExcelObject,Default,Default,Number(($ExcelSheetListArrayMaxIndex+2)),True,True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetCopyMove", "Error copying sheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $aWorkBooks = _Excel_BookList()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookList Example 2", "Error listing Workbooks." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

I'm getting a new error: (pic added)

I belive Its an error for _Excel_SheetCopyMove, according to help: 

5 - Error occurred when copying/moving the sheet. @extended is set to the COM error code. 

Com error: 0

I aslo added extra code to my snipet, because I realized, the error giving part isn't here, so its makes any rescu attempt a "bit tricky".

Képkivágás.JPG

Edited by SorryButImaNewbie
Missing code with the error...

Share this post


Link to post
Share on other sites

This might be a bug in the UDF. Which version of AutoIt do you run?


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

3.3.14.1 right now

Share this post


Link to post
Share on other sites

You need to change the marked line in function _Excel_SheetCopyMove in Excel.au3 to get the COM error code.

If $bCopy Then
        $vSourceSheet.Copy($vBefore, $vAfter)
    Else
        $vSourceSheet.Move($vBefore, $vAfter)
    EndIf
    If @error Then Return SetError(5, @error, 0) ; <== Modify

 


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

#7 ·  Posted (edited)

Ohhh, to what? (I thought the error = 0)

 

So I tried to overwrite excel.au3, but I can't, only with different name (SciTE error)

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

It's a bug so it does not report @error correctly.

Now it is:

If @error Then Return SetError(5, 0, 0)

but it needs to be:

If @error Then Return SetError(5, @error, 0)

 

1 person likes this

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

I understand that, but when I try to save it with 0 replaced by @error , I get an error (pic)

What i think I can do, is to rename it to excel2.au3 or something, and then simply #include that?

(Sorry I like to make sure before I do something I dont understand instead of try and make things worse :) )

Képkivágás2.JPG

Share this post


Link to post
Share on other sites

You do not have write permission to this directory where AutoIt is installed.
Either edit the file as administrator or copy the following code to your script

Func _Excel_SheetCopyMoveEX($oSourceBook, $vSourceSheet = Default, $oTargetBook = Default, $vTargetSheet = Default, $bBefore = Default, $bCopy = Default)
    ; Error handler, automatic cleanup at end of function
    Local $oError = ObjEvent("AutoIt.Error", "__Excel_COMErrFunc")
    #forceref $oError
    Local $vBefore = Default, $vAfter = Default
    If Not IsObj($oSourceBook) Or ObjName($oSourceBook, 1) <> "_Workbook" Then Return SetError(1, 0, 0)
    If $vSourceSheet = Default Then $vSourceSheet = $oSourceBook.ActiveSheet
    If $oTargetBook = Default Then $oTargetBook = $oSourceBook
    If Not IsObj($oTargetBook) Or ObjName($oTargetBook, 1) <> "_Workbook" Then Return SetError(2, 0, 0)
    If $vTargetSheet = Default Then $vTargetSheet = 1
    If $bBefore = Default Then $bBefore = True
    If $bCopy = Default Then $bCopy = True
    If Not IsObj($vSourceSheet) Then
        $vSourceSheet = $oSourceBook.Sheets($vSourceSheet)
        If @error Or Not IsObj($vSourceSheet) Then SetError(3, @error, 0)
    EndIf
    If Not IsObj($vTargetSheet) Then
        $vTargetSheet = $oTargetBook.Sheets($vTargetSheet)
        If @error Or Not IsObj($vTargetSheet) Then SetError(4, @error, 0)
    EndIf
    If $bBefore Then
        $vBefore = $vTargetSheet
    Else
        $vAfter = $vTargetSheet
    EndIf
    If $bCopy Then
        $vSourceSheet.Copy($vBefore, $vAfter)
    Else
        $vSourceSheet.Move($vBefore, $vAfter)
    EndIf
    If @error Then Return SetError(5, @error, 0)
    If $bBefore Then
        Return $oTargetBook.Sheets($vTargetSheet.Index - 1)
    Else
        Return $oTargetBook.Sheets($vTargetSheet.Index + 1)
    EndIf
EndFunc   ;==>_Excel_SheetCopyMoveEX

and replace all function calls to _Excel_SheetCopyMove to _Excel_SheetCopyMoveEX so the modified version gets called.

1 person likes this

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

#11 ·  Posted (edited)

Wow, thanky you so much!

Can I   "Replace owner on subcontainers and objects"  on the folder? Or thats not a good idea? (I try to run as administrator, but I can't, I even tried to make a sgortcut for excel.au3, so I can use the properties/shortcut/advanced to run as admin, but I dont seems to have admin rights for that (its greyed out) which is actually pretty disturbing now that I think about it

Edit:

I tried to run your code, I get an @error = 5, @extended = 1 error on sheet copying

Edit2:

I found @extended = 1 to be the error of Read-only excel object at book_attach, I'm not sure if thats the reason here as well

Edited by SorryButImaNewbie
I save my advantures here instead of posting extras

Share this post


Link to post
Share on other sites

Did you check that all parameters for _Excel_SheetCopyMove have sensible values?
Does $ExcelSheetListArrayMaxIndex hold a sensible value (means the number of a worksheet that exists)?  I'm not sure as you add 2 to the maximum number returned by _ArrayMaxIndex. If you have 5 worksheets in your workbook thn this value shouldn't be > 5.
Use ConsoleWrite/MsgBox to display this values to check.


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

#13 ·  Posted (edited)

According to MsgBox checks, yes, it had a value 1, 1+2 = 3 I had 3 sheets.

I tried Default value, same outcome.

The suspicous part for me is the Excel_SheetList, I displayed that during checking and it returned this, again I have 3 Sheets, none of them can be found in this list.

 

Képkivágás3.JPG

Edit: Also the $ExcelSheetListArrayMaxIndex value is 1. Which doesn't really make sense to me

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

Strange.
Which version of Office do you run?


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

#15 ·  Posted (edited)

I'm not sure.

I have a 2016 "unoffical" version.

Now that I started digging, I found a Shortcut at C:\ProgramData\Microsoft\Windows\Start Menu\Programs, which seems to lead into itself (open containing folder), maybe because its the Start Menu folder

I'm not sure actually (I use it for maybe 2-3 years) according to office download I have an up to date version.

Will Edit for more info

Edit:

Well I may spend some time to install a real office... I'm still a student so I should be able to get a fre copy somehow, but downloading it from a "third party" was much quicker, when I only needed it for some school stuffs and basic use. It was much easier for my younger self...

Thy for the troubelshooting master water!

(verziószám = versionnumber)

Officeversionnumber.JPG

Edit2: I had a windows update, hoped it will solve the problem, it didn't this is my last update today, thanks for the help! (I love this forum)

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

I'm not sure it is caused by the Office version.
Does the _Excel_SheetList.au3 example script work for you? Means - IIRC - you should get 3 sheets listed.
Could it be possible that your workbook contains a lot of hidden sheets?
Are there custom made addons active? I once had problems with a badly written addon driving me crazy!


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

#17 ·  Posted (edited)

I checked for hidden sheets and looked for other VBA shenanigans, but nothing.

I don't know about custom meda addons, but i don't think so.

Excel sheet list gives an "interesting" error. @error = 2 for _Excel_BookOpen meaning 

Specified $sFilePath does not exist, I think this is because its ask for activation first. I added lines

MsgBox($MB_SYSTEMMODAL, " Stop ", "Hammer Time!") 

after the _Excel_BookOpen lines in the _Excel_BookList example, to close these (@error = 2 is avoided this way)

Returns empty array with display, picture of array and one excel (they look the same, empty without sheet, I can go to files and open recently used excels)

However! I can see these excels in System information/Softenvierment/RunningTasks I'm not sure that would usually mean that autoit should see it as well.

I try to open some excels (2 so its like the example) and try to list those, maybe It leads to something

Edit: Okey I tried the booklist example... not sheetlist, Trying with sheet list with the added HammerTime msg box to close the product activation It returns an @error = 1 , I don't know, I try to attach to an excel instance where there is something in the file, and list there... I don't understand I use _excel_SheetList in my code and worked there so far (if array dimensions and size were handeld correctly) it displayed the sheets like it should,

My other "idea" of the origin of the problem is that if I list the _Excel_BookList and display it I get back 3 extra thing. I'm not sure what are these (I wrote a script that goes trhought the array searching for -xls extension, so I can simply skip these) I know what the SOLVER is but I don't know it should be displayed by this function. (see: pic2, arraylist)

Could these XLAM files be the source of my problem to begin with? with some excel extension?

ExcelBookListTest.JPG

ArrayList.JPG

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

I have absolutely no idea what causes your problem :'(
You are sure that you attach to the correct workbook?

Or maybe the problem is caused by the missing activation?


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

I'm pretty sure (there are no other workbooks open, also before I started to upgrade my code to handel arrays, it attached to the workbook and formated the rows/columns inside just nice, so the script was interacting with it before).

Yes, the missing activation is a possible culprit.... You dont't think that these XLAM files are the problem?

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

According to the web:
http://pcsupport.about.com/od/fileextensions/f/xlamfile.htm

"A file with the XLAM file extension is an Excel Macro-Enabled Add-In file that's used to add new functions to Excel."

So this add-ins might influence the way Excel COM (and hence the Excel UDF) works.
You could try to deactivate the add-ins and check if that makes any difference.

Edited by water

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

  • Similar Content

    • Dimmae
      By Dimmae
      Hello,
      at first: i'm new here, so please forgive me my mistakes, and show them to me, just that i can learn to do better in the future.
      Now to my Problem: i have an excel sheet, where i just need some columns for further actions, but i have no idea how to add single columns to a new array.
      I found the following code(the one i just added as a file) from 'water' in this forum, but i wont get how i could add multiple columns into a new array.
      The biggest problem in my situation is that i dont know the count of the rows i need for the array, i just got a fix number of rows, which is 4.
       
      Hope you can help me, and sry again for this 'unlucky illustration'.
       
      btw: how can i add code shown as code here, instead of posting it as a attached file?.
       
       
       
      autoit-select-column.au3
      defects.xlsx
    • czardas
      By czardas
      Haven't had much time to code recently. However the following thread inspired me.
      The debate about linear, parallel and binary search methods was rather interesting and, in an attempt to be diplomatic, I decided to combine @jchd's suggestion with @LarsJ's binary search example. I decided that the binary search algorithm required modification to make it more linear. As usual, 'if you invent something, it probably already exists and if it already exists, it exists for a reason'. My first attempt was not all that good. The code worked but was really a mess. I blame peer pressure (to post an example of a parallel search method).  I will delete that old code in due course.
      With a little memory jogging and a glance at the help file, the solution turned out to be quite easy: I just needed a better understanding of Euler. Further modification will be needed to work with more complicated unicode strings. The output could be returned as an array or a delimitered string. I'm not so interested in those details. I'm just going to post the algorithm for now and anyone, who wants to, can modify it to suit their needs. Both arrays must contain at least 1 element.
      Local $aFoo = [0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,19,20,23,24,26,30,35,39,40,41] Local $aBar = [0,1,5,6,7,8,9,10,11,12,13,14,17,18,19,21,24,25,26,27,34,35,38,40] ParallelExponetialSearch($aFoo, $aBar) ; Compares two lists - returning positive matches. Each input array must be unique (individually) and in alphabetical order. Func ParallelExponetialSearch($aFoo, $aBar) Local $sFind, _ $iMin_F = -1, $iMax_F = UBound($aFoo) -1, $Lo_F = $iMin_F, $Hi_F, _ $iMin_B = -1, $iMax_B = UBound($aBar) -1, $Lo_B = $iMin_B, $Hi_B While $iMin_F < $iMax_F And $iMin_B < $iMax_B ; Toggle Arrays - Which array has most untested elements? This is the one we want to search next, ; so we can bypass more comparisons because (in theory) mismatches have a greater chance of being skipped. If $iMax_F - $iMin_F >= $iMax_B - $iMin_B Then ; $aFoo has more (or an equal number of) untested elements $Hi_F = $iMax_F $iMin_B += 1 $sFind = $aBar[$iMin_B] While $Lo_F < $Hi_F ; search $aFoo For $i = 0 To Floor(Log($Hi_F - $Lo_F) / Log(2)) $Lo_F = $iMin_F + 2^$i If $aFoo[$Lo_F] = $sFind Then $iMin_F = $Lo_F ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $Lo_F & "] = $aBar[" & $iMin_B & "]" & @LF) ExitLoop 2 ElseIf $aFoo[$Lo_F] > $sFind Then $Hi_F = $Lo_F -1 $iMin_F += Floor(2^($i -1)) $Lo_F = $iMin_F ContinueLoop 2 EndIf Next $iMin_F = $Lo_F ; minimum increment is one WEnd Else ; $aBar has more untested elements $Hi_B = $iMax_B $iMin_F += 1 $sFind = $aFoo[$iMin_F] While $Lo_B < $Hi_B ; search $aBar For $i = 0 To Floor(Log($Hi_B - $Lo_B) / Log(2)) $Lo_B = $iMin_B + 2^$i If $aBar[$Lo_B] = $sFind Then $iMin_B = $Lo_B ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $iMin_F & "] = $aBar[" & $Lo_B & "]" & @LF) ExitLoop 2 ElseIf $aBar[$Lo_B] > $sFind Then $Hi_B = $Lo_B -1 $iMin_B += Floor(2^($i -1)) $Lo_B = $iMin_B ContinueLoop 2 EndIf Next $iMin_B = $Lo_B ; minimum increment is one WEnd EndIf WEnd EndFunc ;==> ParallelExponetialSearch I hope this will be useful to someone. I believe it deserved a thread of its own!
    • RC86
      By RC86
      Afternoon!
      I have a requirement to return both a string and an array from a function so as a result I put them both into an array and returned that.  I can access them in their entirety after returning them but then I can't seem to access the array elements after this.  Should I be able to or is there a prettier way?
      #include <Array.au3> ;Memory info returned as a string and an array $memoryInfo = _getMemoryInfo() msgbox(0,"Memory Info",$memoryInfo[0]) _ArrayDisplay($memoryInfo[1],"Memory as an Array") Local $newArray[7] $memoryInfo[1] = $newArray msgbox(0,"Test element",$newArray[0]) _ArrayDisplay($newArray) Func _getMemoryInfo() Local $newArray[7] Local $array = MemGetStats() $newArray[0] = $array[0] ;% of memory in use $newArray[1] = Round($array[1]/1024 * 0.001,2) ;Total physical RAM $newArray[2] = Round($array[2]/1024 * 0.001,2) ;Availaible physical RAM $newArray[3] = Round($array[3]/1024 * 0.001,2) ;Total pagefile $newArray[4] = Round($array[4]/1024 * 0.001,2) ;Available pagefile $newArray[5] = Round($array[5]/1024 * 0.001,2) ;Total virtual $newArray[6] = Round($array[6]/1024 * 0.001,2) ;Available virtual $memoryUsage = $newArray[1] - $newarray[2] $pagefileUsage = $newArray[3] - $newarray[4] ;Output/Return Local $returnArray[2] $returnArray[0] = "Memory: " & $memoryUsage & " GB/" & $newArray[1] & " GB " & @CRLF & "Pagefile: " & $pagefileUsage & " GB/" & $newArray[3] & " GB " $returnArray[1] = $newArray return $returnArray EndFunc A bit messy but hopefully it's understandable what I'm trying to achieve.
      Thanks!
    • Jibberish
      By Jibberish
      I am having difficulties getting updated results from GUICtrlCreateInput. I wrote a small script to demonstrate what I am trying to do.
      This script reads a text file into an array and displays the Name and Number from the text file.
      The user can check a name and change the number, and the results are displayed in _ArrayDisplay.
      Only the Checked names are displayed in their original position. This is necessary for future
      plumbing.
      The problem with this script is the original number is returned, not the changed number. I cannot
      figure out how to get the updated number to be displayed.
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; This script reads a text file into an array and displays the Name and Number from the text file. ; The user can check a name and change the number, and the results are displayed in _ArrayDisplay. ; Only the Checked names are displayed in their original position. This is necessary for future ; plumbing. ; ; The problem with this script is the original number is returned, not the changed number. I cannot ; figure out how to get the updated number to be displayed. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include-once #include <MsgBoxConstants.au3> #include <array.au3> #include <Date.au3> #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <Misc.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Local $iMax = 6 ;Default number of Videos - 1 for the array counter Dim $aTextFile[$iMax][2] ; [start with 5 entries][Name, Number] Don't get confused! [Row][Column] Local $i = 0 Local $iLeft = 30 Local $iTop = 30 Local $sName Local $sNumber Local $aArray Local $iMaxCol = 5 Local $iRow = 0 Local $iCol = 0 Local $aNumberCount[$iMaxCol][2] $aArray1 = ReadFile() $aNamesNumbers = DisplayNames($aArray1) _ArrayDisplay($aNamesNumbers) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; ReadFile() places the contents of the NameNumber.txt file in an array ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func ReadFile() Local $sFileData = @ScriptDir & "\NameNumber.txt" Local $iStrReturn = 0 Local $aArrayFile Local $aTextFile[$iMaxCol][2] Local $aName Local $sCheckBox1 Const $iL = 10 ; Count from Left for GUI so all buttons line up Local $sFill Local $iA = 0, $iN = 0 ; Put the Names into an Array _FileReadToArray($sFileData, $aArrayFile) For $iA = 0 To $aArrayFile[0] ; Step through the array looking for Names If StringInStr($aArrayFile[$iA], "Name:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next $iCol = 1 $iRow = 0 $sFill = "" For $iA = 1 To $aArrayFile[0] ; Step through the array looking for Numbers If StringInStr($aArrayFile[$iA], "Number:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next Return $aTextFile EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the Name and Number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayNames($aArray1) Local $aName[$iMax] Local $aNumbers[$iMax] $iMMCount = UBound($aArray1) $iMMCount -=1 Local $iWidth = 300 Local $iLength = 300;$iMMCount * 30 GUISetFont(12) $hGUI = GUICreate("Edit / Update Number Test", $iWidth, $iLength, -1, -1) GUICtrlCreateLabel(" Name Number",1,5) ;$iTop += 30 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display Name with a Checkbox. Only Checked Names should be saved. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For $i = 0 to $iMMCount Step 1 $sNameText = $aArray1[$i][0] $iNameLength = StringLen($sNameText) $aName[$i] = GUICtrlCreateCheckbox($sNameText,$iLeft, $iTop) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the number from the text file below each name. Allow the user to change the number and display the ; new number. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iLeft = 60 GUIStartGroup() $iTop = 28 For $i = 0 to $iMMCount Step 1 $sNumberText = $aArray1[$i][1] $aNumberCount[$i][1] = $sNumberText $aNumberCount[$i][0] = GUICtrlCreateInput($sNumberText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aNumberCount[$i][0],200) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read the checked names and (possibly updated) number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iMMCount = UBound($aNumberCount) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedNameNumber[$iMMCount][2] $iLeft = 30 Local $idCloseGUI = GUICtrlCreateButton("Close",$iLeft, $iTop) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aName[$i]) Case $GUI_CHECKED $aCheckedNameNumber[$i][0] = $aArray1[$i][0] Case $GUI_UNCHECKED EndSwitch Switch GUICtrlRead($aNumberCount[$i][0]) Case $aCheckedNameNumber[$i][1] = GUICtrlRead($aNumberCount[$i][1]) EndSwitch Next ExitLoop EndSwitch WEnd For $i = 0 to $iMMNewCount step 1 GUICtrlRead($aNumberCount[$i][0]) If $aCheckedNameNumber[$i][0] <> "" Then $aCheckedNameNumber[$i][1] = $aNumberCount[$i][1] EndIf Next GUIDelete($hGUI) Return $aCheckedNameNumber EndFunc This is the text file I am reading. If you want to try this out put the NameNumber.txt file in your script directory. It's attached to the post.
      * This is a dummy file with a Name and Number * The only purpose of this file is to read the updated Number. Name:Taggart Number:916 Name:Mongo Number:90 Name:Hedley Lamarr Number:22 Name:Bart Number:9999 Name:The Waco Kid Number:2244 If I change the number, the original number is displayed at the end, not the updated/modified number. I need the modified number to be displayed.
      Thanks in advance for any assistance!
      Jibberish
      NameNumber.txt
    • Jibberish
      By Jibberish
      I am working on a Video Player Test Script. I am reading a text file into a 3d array to be displayed in a GUI.
      Array Content:
      [x][0]FileName.mp4
      [x][1]UsageCount -> Up to a 4 digit number
      [x][2]EnableUsageCount (True/False)
      In the GUI the user can check the filename box, edit the number of usages and check EnableUsageCount to turn on the UsageCount control using the UsageCount number for the maximum number of plays.
      To make this easier to deal with I have removed the EnableUsageCount section, and am just concentrating on getting a method to put the edited (or unchanged) UsageCount in the array. Currently nothing is read into the array, due to my using the wrong method in the Case statement.
      Here are code snippets of what I am trying to do:
      ; Snippets from script ; I read the text file at the bottom and put the .mp4 filenames in $aManifest[x][0] and UsageCount in $aManifest[x][1] ; Then I create a GUI to display the .mp4 filenames with checkboxes and the UsageCount to the right. UsageCount is editable by the user. ; If the filename is checked, I want to read the filename into $aCheckedVideos[x][0] and the updated UsageCount in $aCheckedVideos[x][1] ; The GUICtrlRead($aVideoName[$i]) with Case $GUI_CHECKED & UNCHECKED works for the checkboxes ; This section puts the filenames in the GUI with a checkbox For $i = 0 to $iMMCount Step 1 $sMP4Text = $aManifest[$i][0] $iMP4Length = StringLen($sMP4Text) $aVideoName[$i] = GUICtrlCreateCheckbox($sMP4Text,$iLeft, $iTop) $iTop += 30 Next ; This section reads numbers from the Manifest array, and I want to be able to change the number and have them saved. ; So the Case $GUI_CHECKED & UNCHECKED won't work here, and I can't figure out what I should be doing here. For $i = 0 to $iMMCount Step 1 $sUsageText = $aManifest[$i][1] $aUsageCount[$i] = GUICtrlCreateInput($sUsageText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aUsageCount[$i],200) $iTop += 30 Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aVideoName[$i]) Case $GUI_CHECKED $aCheckedVideos[$i][0] = $aManifest[$i][0] ; If checked, I put the results into a two D array Case $GUI_UNCHECKED ; where Video Name is $aCheckedVideos[x][0] EndSwitch Switch GUICtrlRead($aUsageCounter[$i]) Case $GUI_CHECKED $aCheckedVideos[$i][1] = $aUsageCount[$i] ;I want to put the text (numbers) in $aCheckedVideos[x][1] Case $GUI_UNCHECKED ;but what is returned is blank, probably due to EndSwitch ; $GUI_CHECKED being the wrong thing. Next ExitLoop EndSwitch WEnd ;The txt file I'm reading has the following: ;~ /** Title #1: Big Buck Bunny 1080p **/ ;~ "Name": "Big Buck Bunny", ;~ "URI": "..\\MediaFiles\\bbb_1080_60s.mp4", ;~ "UsageCount": 9999, ;~ "URI": "..\\MediaFiles\\bbb_1080_60s_enc1.mp4", ;~ "UsageCount": 45, ;~ "URI": "..\\MediaFiles\\bbb_1080_60s_enc1.mp4", ;~ "UsageCount": 2, ;~ /** Title #2: Tears of Steel 4K **/ ;~ "Name": "Tears of Steel 4K", ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC.mp4", ;~ "UsageCount": 9876, ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC_enc2.mp4", ;~ "UsageCount": 0, ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC_enc2.mp4", ;~ "UsageCount": 5, I am certain that the section
                          Switch GUICtrlRead($aUsageCounter[$i])
                              Case $GUI_CHECKED
                                  $aCheckedVideos[$i][1] = $aUsageCount[$i]    ;I want to put the text (numbers) in $aCheckedVideos[x][1]
                              Case $GUI_UNCHECKED                                ;but what is returned is blank, probably due to
                          EndSwitch                                            ; $GUI_CHECKED being the wrong thing.

      is wrong, and this is what I am looking for help with. Instead of $GUI_CHECKED what should I be looking for?
      The worst part of this is I had this working late last night, and then lost my changes and cannot for the life of me remember how I had this working.
      Help is truly appreciated!
      Jibberish