Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetFiles()

Status
Not open for further replies.

wp1

Programmer
Jun 5, 2013
19
US

i am using the directory.getfiles feature. I have 169 files i am sifting through to grab filenames that match user input. My array is folderFiles that is setup for 200 slots. No matter what i do, when i run this line of code:

folderFiles = System.IO.Directory.GetFiles(folderPath)

I get index out of bounds alarm. Well i put a break point at the above line of code and it shows a length of 201. I believe this is creating the alarm BUT i don't know what to do. I have changed the array length and it is ALWAYS 1 more than what i set my array size to. It makes no sense to me, do i just need to error trap? Help? Below is a snippet of code. It errors when i go to access the array in the 'if' statement.




Do Until n = 200
folderFiles(n) = "NA"
n = n + 1
Loop
n = 0
'format date
x1 = Format(Now, "MMddyyyy")
'get file names
folderFiles = System.IO.Directory.GetFiles(folderPath)
'outside loop sifts through filenames retreived from "folderPath" string array
Do Until n = 169
If folderFiles(n) <> "NA" Then
n4 = n4 + 1
End If
n = n + 1
 
NEVERMIND THE FIRST QUESTIONS! I don't think my getfiles is working. it looked like my array was being reset with nothing in it. looking into that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top