Jump to content

Arrays and For/Next loops


 Share

Recommended Posts

This is more of a conceptual question. I have the following code:

#Include <Array.au3>

$BackupFiles = _ArrayCreate("C:\1.xls", "C:\2.xls", "C:\3.xls")

$xlApp = ObjCreate("Excel.Application")
If Not IsObj($xlApp) Then Exit

With $xlApp
    .Visible = False
    .Workbooks.Open("C:\BackupMacros.xls")
    For $i = 0 to UBound($BackupFiles) - 1
        .Run("AutoItBackup(" & chr(34) & $BackupFiles[$i] & chr(34) & ")")
    Next
    .Quit
    msgbox(0, "", "done")
EndWith

What I'm basically doing is running a macro on a bunch of different Excel files. This all works just as expected. The issue I've noticed is that if my array has only 2 elements, my code runs the macro on the first element twice. So if I change my array to only include 2 files instead of 3, and make no other changes, the macro I'm executing will run on the first file twice. If the array has 3 or more file this doesn't happen. Does anyone know what's going on?

Thanks.

Link to comment
Share on other sites

I can't reproduce this problem. Also, like Richard said, don't use _ArrayCreate anymore (It's not in the latest SciTE anymore, even.)

I had to comment out the Excel lines, because I don't have the 1.xls, 2.xls and 3.xls files.

#include <Array.au3>

Dim $BackupFiles[2] = ["C:\1.xls", "C:\2.xls"]

;$xlApp = ObjCreate("Excel.Application")
;If Not IsObj($xlApp) Then Exit

;With $xlApp
;    .Visible = False
;    .Workbooks.Open("C:\BackupMacros.xls")
    For $i = 0 to UBound($BackupFiles) - 1
        ConsoleWrite("$BackupFiles[" & $i & "] = " & $BackupFiles[$i] & @CRLF)
;        .Run("AutoItBackup(" & chr(34) & $BackupFiles[$i] & chr(34) & ")")
    Next
;    .Quit
;    msgbox(0, "", "done")
;EndWith

$BackupFiles = _ArrayCreate("C:\1.xls", "C:\2.xls")

;$xlApp = ObjCreate("Excel.Application")
;If Not IsObj($xlApp) Then Exit

;With $xlApp
;    .Visible = False
;    .Workbooks.Open("C:\BackupMacros.xls")
    For $i = 0 to UBound($BackupFiles) - 1
        ConsoleWrite("$BackupFiles[" & $i & "] = " & $BackupFiles[$i] & @CRLF)
;        .Run("AutoItBackup(" & chr(34) & $BackupFiles[$i] & chr(34) & ")")
    Next
;    .Quit
;    msgbox(0, "", "done")
;EndWith
Edited by Manadar
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...