NiceBoy1234 Posted January 5, 2016 Posted January 5, 2016 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 ... EndIfI 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]
orbs Posted January 5, 2016 Posted January 5, 2016 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 WinPose - simultaneous fluent move and resize 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 Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
NiceBoy1234 Posted January 5, 2016 Author Posted January 5, 2016 (edited) No Next should not be after If Endif, so after the for loop I have to declare my "i" like $i = 0.Thus what do you mean excatly with 1-D?nevermind 1 Dimensional Edited January 5, 2016 by NiceBoy1234
NiceBoy1234 Posted January 5, 2016 Author Posted January 5, 2016 Ok I did _ArrayDisplay() and it's 1 Dimensional.
NiceBoy1234 Posted January 5, 2016 Author Posted January 5, 2016 I gave $i a valid value after the looop but did not solve it either
InunoTaishou Posted January 5, 2016 Posted January 5, 2016 (edited) 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 January 5, 2016 by InunoTaishou
orbs Posted January 5, 2016 Posted January 5, 2016 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 WinPose - simultaneous fluent move and resize 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 Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
NiceBoy1234 Posted January 5, 2016 Author Posted January 5, 2016 _ArrayDisplay showed a window with this:[0] = "xxx"[1] = "xxx"[2] = "xxx"
orbs Posted January 5, 2016 Posted January 5, 2016 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 WinPose - simultaneous fluent move and resize 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 Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
NiceBoy1234 Posted January 5, 2016 Author Posted January 5, 2016 $i stands for [0][1][2] or not?,it jsut showed[0] = "xxx"[1] = "xxx"[2] = "xxx"
orbs Posted January 5, 2016 Posted January 5, 2016 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 WinPose - simultaneous fluent move and resize 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 Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now