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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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

#18 ·  Posted

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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#19 ·  Posted

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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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

    • StillLearningThisStuff
      Merge 2 x 1d temp arrays into one 2d array
      By StillLearningThisStuff
      Hello all,
      Summary: I have a basic piece of code that is to be a part of a much larger project; I just can't seem to get the right output. I'm retrieving two lots of powershell data into 2 x 1d arrays and trying to add them into a single 2d array. Retrieving the data together into the 2d array seemed harder, due to the application names varying too much to string split. Data being pulled is application name and GUID. From here I will use this info in a drop down box and an uninstall button to run the required command to remove the selected software (have this sorted already).
      Problem: When I merge the data it doesn't put the application name and GUID on the same row in differing columns eg. my test box has 24 applications plus some superfluous data from Powershell to be cleaned up by the _arraydeletes. Instead I end up with an array with 58 rows and 2 columns; whereas my temp 1d arrays have 28 rows. As you can see I've tried both _ArrayInsert and _ArrayAdd but I still get the same result.
      Question: Is there something that I'm doing wrong in putting the data into the 2d array or do I just need to do some more post processing to tidy it up and align the names and GUIDs?
      Code:
      #include <Array.au3> $Cmd1 = (" /c Powershell.exe " & Chr(34) & "Get-WmiObject -Class win32reg_addremoveprograms | where {$_.ProdID -like " & Chr(34) & Chr(123) & Chr(42) & Chr(125) & Chr(34) & "} | select DisplayName" & Chr(34)) $Cmd2 = (" /c Powershell.exe " & Chr(34) & "Get-WmiObject -Class win32reg_addremoveprograms | where {$_.ProdID -like " & Chr(34) & Chr(123) & Chr(42) & Chr(125) & Chr(34) & "} | select ProdID" & Chr(34)) Global $aNameGUID[1][2] ;_ArrayDisplay($aNameGUID) ReadApps($Cmd1,0) ;_ArrayDisplay($aNameGUID) ReadApps($Cmd2,1) _ArrayDisplay($aNameGUID) Terminate() Func ReadApps($Command,$col) $DOS = Run(@ComSpec & $Command, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($DOS) $DOSOut = StdoutRead($DOS) ;MsgBox(0,"Data",$DOSOut) ;Show the line items that we want in the array Local $tmpArray = StringSplit(StringTrimRight(StringStripCR($DOSOut), StringLen(@CRLF)), @CRLF) If @error Then MsgBox(0,"FAIL","I failed to find objects") Exit Else _ArrayDisplay($tmpArray) EndIf ;_ArrayDelete($tmpArray, 3) ;_ArrayDelete($tmpArray, 2) ;_ArrayDelete($tmpArray, 1) ;$tmpArray[0] = $tmpArray[0] - 3 For $i = 0 To UBound($tmpArray) - 1 ;_ArrayAdd($aNameGUID, $tmpArray[$i], $col) _ArrayInsert($aNameGUID, 0, $tmpArray[$i], $col) Next $tmpArray = 0 EndFunc ;==>ReadApps While 1 Sleep(1500) WEnd Func Terminate() Exit 0 EndFunc ;==>Terminate Thanks in advance,
      Luxyboy
    • harvester2001
      Refresh array after one loop
      By harvester2001
      Hi
      I need some help.
      I try ping computers from targets.txt (I have computer name in lines) if they ping I want do something and after that remove pc name from targets.txt. It`s working but problem is when I put this inside loop, because I need run script until all computers will not be removed from the list (targets.txt). I don`t know how to "refresh" array
      Please help
      #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Local $PC_list = "\targets.txt" Local $bTargets = FileReadToArray(@ScriptDir& $PC_list) Do _check_ping() ;count_lines Local $file_count_lines = _FileCountLines(@ScriptDir& $PC_list) $i = $file_count_lines ConsoleWrite("na liście "&$i & @CRLF) Until $i = 0 ; IF &i = 0 then show MsgBox MsgBox(1, "xXx", "Finish") ;PING Func _check_ping() For $sPC In $bTargets $var = Ping($sPC, 250) If $var Then ConsoleWrite($sPC &"online"& @CRLF) ;Do something ;Delete $sPC from targets.txt Local $_Array _FileReadToArray ( @ScriptDir& "\targets.txt", $_Array ) $_Array = _DeleteArrayElementWithStringInstr ( $_Array, $sPC ) _FileWriteFromArray ( @ScriptDir& "\targets.txt", $_Array, 1 ) Sleep(200) Else ConsoleWrite($sPC &"offline"& @CRLF) EndIf Next EndFunc ;DELETE LINE FROM TXT Func _DeleteArrayElementWithStringInstr ( $_Array, $_String ) Local $_Item For $_Element In $_Array If StringInStr ( $_Element, $_String ) <> 0 Then _ArrayDelete ( $_Array, $_Item ) Else $_Item+=1 EndIf Next Return ( $_Array ) EndFunc ;==> _DeleteArrayElementWithStringInstr ( )  
    • j0kky
      Assign a value to an array in array element
      By j0kky
      Hi guys,
      talking about array in array, I would like to directly assign a value to an element in an array contained in another array.
      While it is quite simple to access the value if it is already setted:
      Local $a[3] = [1, 2], $b[2] = [3, 4] $a[2] = $b ConsoleWrite(($a[2])[0] & " " & ($a[2])[1] & @CRLF) If I try to write directly to the element, I get an error:
      Local $a[3] = [1, 2] Local $b[2] $a[2] = $b ($a[2])[0] = 1 Is assigning first every value of the contained array and then including it in the container the only way?
    • SorryButImaNewbie
      AutoIt script turns off, because of array is out of bound
      By SorryButImaNewbie
      Hello all!
      I wrote a little script to automate some of my work (for which I'm greatfull).
      I have little problem now. My script get data of currency values from specified time period. The problem, if XY day is a holiday or something, then the bank doesn't have new values for that day, thus my script can ask for "till that date" if there is only data for "till that date-1".
      I should be done with this for tomorrow and I should learn for my test paper tomorrow, make a genetic algorhytm homework, and at least look at a ppt...
      So here is my code, pleas ask if you need more information!
      InternetRead2() ;Creating Date and Arfolyam arrays, using DateInterval read from above (_ArraysDisplayed and function is "tested") ;Calculate and write HUF*OSSZEG Do Local $SZAMLATELJOlvaso = _Excel_RangeRead($ExcelObject, Default, $SZAMLATELJoszlop & $CellaOlvasoSzamlalo) Local $Time = StringTrimRight($SZAMLATELJOlvaso, 6) $DateArrayTimeIndex = _ArraySearch($DateArray, $Time, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) If @error = 6 Then $DateArrayTimeIndex = _ArraySearch($DateArray, $Time-1, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) EndIf If @error = 6 Then $DateArrayTimeIndex = _ArraySearch($DateArray, $Time-2, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) EndIf If @error = 6 Then $DateArrayTimeIndex = _ArraySearch($DateArray, $Time-3, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) EndIf If @error = 6 Then $DateArrayTimeIndex = _ArraySearch($DateArray, $Time-4, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) EndIf $DateArrayTimeIndex = $DateArrayTimeIndex+1 ;Egyébként arraysearch -1et ad vissza, 0nál. Passz Sleep(200) If Not $SZAMLATELJOlvaso = "" Then _Excel_RangeWrite($ExcelObject, $ExcelObject.Activesheet, "=" & $OSSZEGoszlop & $CellaOlvasoSzamlalo & "*" & String($ArfolyamArray[$DateArrayTimeIndex]) & "", String($sHUFBeszurOszlop) & $CellaOlvasoSzamlalo) If @error Then _Excel_RangeWrite($ExcelObject, $ExcelObject.Activesheet, "=" & $OSSZEGoszlop & $CellaOlvasoSzamlalo & "*" & String($ArfolyamArray[$oXML_Node.Length]) & "", String($sHUFBeszurOszlop) & $CellaOlvasoSzamlalo) MsgBox(64, "Értesítés", "Valamilyen okból, nem találok az adott dátumhoz árfolyamot, a keresési idők közül a legutolsó árfolyammal töltöttem ki!" & @CRLF & Number($oXML_Node_Datum)) EndIf EndIf $CellaOlvasoSzamlalo = $CellaOlvasoSzamlalo + 1 Until $SZAMLATELJOlvaso = "" also my internetread2 function :
      Func InternetRead2() ;ezt használja az excelmove ;----------------------------------- ;Original Source: https://www.autoitscript.com/forum/topic/184884-solved-basic-com-help-working-on-string-returned-from-api-mi-doing-this-okey/ ;by Genius257 ;TO DO: Some error handling maybe: what if there is no $MinTime/$MaxTime? ;Read the returns in to array for future use --> Right now, 2 arrays one with the dates and one with the exchangerates ;----------------------------------- ;Globals decleared to avoid warnings Global $MinTime ;20160601000000 Global $MaxTime ;20160610000000 Global $MinTimeFormated = StringTrimRight($MinTime, 6) Global $MaxTimeFormated = StringTrimRight($MaxTime, 6) $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") If $MaxTimeFormated = "" and $MinTimeFormated = "" Then MsgBox(64, "Értesítés", "Nincsenek beolvasott dátumok a memóriában, dummy dátumokat adok meg!" & @CRLF & "20160901, 20160910") $MinTimeFormated = "20160901" $MaxTimeFormated = "20160905" EndIf $oHTTP.Open("GET", "http://api.napiarfolyam.hu/?bank=mnb&valuta=eur&datum="&$MinTimeFormated&"&datumend="&$MaxTimeFormated&"", False) $oHTTP.Send() $sXML = $oHTTP.responseText Global $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.loadXML( $sXML ) $oXML_Nodes = $oXML.SelectNodes("./arfolyamok/deviza/item") Global $ArfolyamArray[$oXML_Nodes.Length] ;MsgBox(64, "Title", "" & $oXML_Nodes.Length & "") ;_ArrayDisplay($ArfolyamArray) Global $DateArray[$oXML_Nodes.Length] For $i=0 To $oXML_Nodes.Length-1 Global $oXML_Node = $oXML_Nodes.Item($i) $oXML_Node_Bank = $oXML_Node.SelectNodes("./bank") $oXML_Node_Bank = $oXML_Node_Bank.Length>0?$oXML_Node_Bank.Item(0).text:"" Global $oXML_Node_Datum = $oXML_Node.SelectNodes("./datum") $oXML_Node_Datum = $oXML_Node_Datum.Length>0?$oXML_Node_Datum.Item(0).text:"" $oXML_Node_Penznem = $oXML_Node.SelectNodes("./penznem") $oXML_Node_Penznem = $oXML_Node_Penznem.Length>0?$oXML_Node_Penznem.Item(0).text:"" $oXML_Node_Kozeps = $oXML_Node.SelectNodes("./kozep") $oXML_Node_Kozep01 = $oXML_Node_Kozeps.Length>0?$oXML_Node_Kozeps.Item(0).text:"" $oXML_Node_Kozep02 = $oXML_Node_Kozeps.Length>1?$oXML_Node_Kozeps.Item(1).text:"" $ArfolyamArray[$i] = $oXML_Node_Kozep01 $DateArray[$i] = StringTrimRight(StringReplace($oXML_Node_Datum, "-", ""), 8) ConsoleWrite( "Match [" & StringFormat("%02i", $i+1) & "]:"&@CRLF& _ @TAB&"Bank: "&@TAB&$oXML_Node_Bank&@CRLF& _ @TAB&"Datum: "&@TAB&$oXML_Node_Datum&@CRLF& _ @TAB&"Penznem: "&@TAB&$oXML_Node_Penznem&@CRLF& _ @TAB&"Kozep01: "&@TAB&$oXML_Node_Kozep01&@CRLF& _ @TAB&"Kozep02: "&@TAB&$oXML_Node_Kozep02&@CRLF _ ) Next ;_ArrayDisplay($ArfolyamArray) ;_ArrayDisplay($DateArray) EndFunc My problem is that I have dates in my excel till 2016.10.30, but I only have dates till 28.
      (see the api, according to aoutit console, I have the same data: http://api.napiarfolyam.hu/?bank=mnb&valuta=eur&datum=20161001&datumend=20161030 )
      My idea/goal (with the If @error then... after @SZAMLATELJolvaso part) is that if this happens, I want it to automaticly jump to the last date of the array (I will be able to write something more elaborate, but for now thats my goal, to save the sinking ship )
      Thank yu for your help and insight!
    • skybax
      Array to Listview
      By skybax
      Good morning all,
      I have a question regarding a situation im in...
       
      I have an array with information from sql query, how can i send this information to a listview ?
       
      $citeste_daune = "SELECT `id_dauna`,`data_incident`,`sala`,`autor`,`suma` FROM `daune` WHERE `status`=1;" $sa_citit_daune = _query($sqlinstance, $citeste_daune) Global $aresult[10001][5] = [[10000, 5]] Global $iindex = 0 With $sa_citit_daune While NOT .eof $aresult[$iindex][0] = .fields("id_dauna").value $aresult[$iindex][1] = .fields("data_incident").value $aresult[$iindex][2] = .fields("sala").value $aresult[$iindex][3] = .fields("autor").value $aresult[$iindex][4] = .fields("suma").value $iindex = $iindex + 1 .movenext WEnd EndWith ReDim $aresult[$iindex][5] $aresult[0][0] = $iindex - 1 _ArrayDisplay($aresult) GUICtrlCreateListViewItem(_ArrayToString($aresult), $lista_daune_active)  
      This is what i see when i execure _ArrayDisplay($aresult)