Jump to content

Get Array Index of for loop in if statement


Recommended Posts

How can I access a variable with its index of a loop inside my if statment.

Code:
 

For $i = 0 To UBound($aFileListFootageFolderRe_01) - 1
      ...
      Next

     If $getTimeNewFootageFolderInit_01 <> $getTimeNewFootageFolder_01 And $aFileListFootageFolderRe_01[$i] == 11) Then
      ...
     EndIf

I get following error while doing this:
 

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

Thus the error points at this

$aFileListFootageFolderRe_01[$i]
Link to comment
Share on other sites

to debug, before the "For" section, call _ArrayDisplay() to make sure the array exists and is 1-D.

also, i assume you mean the "Next" line should be after the If...EndIf, so it is inside the loop and performed over every element, right? if not, then make sure $i has a valid value after the loop is done.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

You could use _ArraySearch to get the index of the value you're looking for

#include <Array.au3>
Global const $aValues[] = ["This", "Is", "a", "test", "AutoIt", "Rulez!"]
Global const $sValueToFind1 = "AutoIt"
Global const $sValueToFind2 = "Cake"
Global const $iIndex1 = _ArraySearch($aValues, $sValueToFind1)
Global const $iIndex2 = _ArraySearch($aValues, $sValueToFind2)

If ($iIndex1 > -1) Then
    MsgBox("", "", "Found '" & $aValues[$iIndex1] & "' at index " & $iIndex1)
Else
    MsgBox("", "", "Could not find the value '" & $sValueToFind1 & "' for index $iIndex1")
EndIf

If ($iIndex2 > -1) Then
    MsgBox("", "", "Found '" & $aValues[$iIndex2] & "' at index " & $iIndex2)
Else
    MsgBox("", "", "Could not find the value '" & $sValueToFind2 & "' for index $iIndex2")
EndIf

 

Edited by InunoTaishou
Link to comment
Share on other sites

please attach a screenshot of _ArrayDisplay (or a console output you can generate with this) and the value of $i right before the offending "If".

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

and $i ...?

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

add this line before the offending "If" line:

ConsoleWrite('$i = ' & $i & @CRLF)

$i should be an integer. 0, 1 or 2 are valid values in this case.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

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

×
×
  • Create New...