Jump to content
Sign in to follow this  
7121

Return Value for incorrect number in Array variable

Recommended Posts

7121

I wish to know is there a return value whenever the array variable has an incorrect?

#Include <File.au3>
#Include <Array.au3>
$sFilter = ""
$iFlag = ""
$FileList=_FileListToArray(@DesktopDir)
If @Error=1 Then
    MsgBox (0,"","No Folders Found.")
    Exit
EndIf
If @Error=4 Then
    MsgBox (0,"","No Files Found.")
    Exit
EndIf
$msg = MsgBox(0, "", $FileList[23] )

_ArrayDisplay($FileList,"$FileList")

\Desktop\Testing.au3 (14) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If not, is there a way to sort of EXIT, before the last number is hit or some way to detect that it's at the end?

Share this post


Link to post
Share on other sites
Yoriz

When using '_FileListToArray' index zero of the array returns the Number of Files\Folders found.

using the following would show all the indexs without going out of range.

For $i = 1 To $FileList[0]
    MsgBox(0, $i, $FileList[$i])
Next
Edited by Yoriz

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites
enaiman

Always use UBound for arrays. That's the no. 1 measure against errors of that kind.

#Include <File.au3>
#Include <Array.au3>
$sFilter = ""
$iFlag = ""
$FileList=_FileListToArray(@DesktopDir)
If @Error=1 Then
    MsgBox (0,"","No Folders Found.")
    Exit
EndIf
If @Error=4 Then
    MsgBox (0,"","No Files Found.")
    Exit
EndIf
If UBound($FileList)-1 >= 23 Then 
    $msg = MsgBox(0, "", $FileList[23] )
Else
    $msg = MsgBox(0, "", $FileList[UBound($FileList)-1] )
EndIf

_ArrayDisplay($FileList,"$FileList")

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
jchd

As explained above, always carefully check the upper bound of an array before accessing its elements.

Or else it's going to be as much sensical to the interpretor as if I ask you to give me what you're holding in your 5th hand. You're likely to look at me strangely and think I'm in a state of sin.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
7121

When using '_FileListToArray' index zero of the array returns the Number of Files\Folders found.

using the following would show all the indexs without going out of range.

For $i = 1 To $FileList[0]
    MsgBox(0, $i, $FileList[$i])
Next

THANK YOU THANK YOU!, that really worked for me.

I have another question however, i noticed that the array seems to list the files by DATE and TIME, anyway to sort it by name instead?

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
Sign in to follow this  

×