dropdown list array problem

D

djharrison

I have managed to populate a dropdown box with a list of all files in
the current folder and even filtered them by the extension so that it
only displays the .mdb files. However, the menu seems to be holding
all of the items in the folder and displaying only the .mdb. This
seems to be a problem with the way I am defining the size of the
array. If I add my .mdb filter to the array loop I get an 'out of
range' error for the n variable?? Can anyone suggest a solution??


'Find Number of Files
varFileCount = 0

For Each objFile in objFolder.Files
varFileName = objFSO.GetFileName(objFile.Name)
varFileType = objFSO.GetExtensionName(objFile.Name)
If (Left(varFileType, 3) = "mdb") Then
varFileCount = varFileCount + 1
End if
Next

' Put File Names into an Array
ReDim varFileNames(varFileCount)
n = 0

For Each objFile in objFolder.Files
n = n + 1

' varFileName = objFSO.GetFileName(objFile.Name)
' varFileType = objFSO.GetExtensionName(objFile.Name)
' If (Left(varFileType, 3) = "mdb") Then

varFileNames(n) = objFile.Name

' End If

Next
 
R

Ray at

You can chuck all your filenames in an array like so. Note the usage of the
dynamic array dimmed with () and then Redimmed through the loop.


<%
Dim aFiles()
varFileCount = 0

For Each objFile in objFolder.Files
varFileName = objFSO.GetFileName(objFile.Name)
varFileType = objFSO.GetExtensionName(objFile.Name)
If (Left(varFileType, 3) = "mdb") Then

Redim Preserve aFiles(varFileCount)
aFiles(varFileCount) = varFileName

varFileCount = varFileCount + 1
End if
Next

Set objFolder = Nothing
Set objFSO = Nothing
%>

<select>
<% For i = 0 To UBound(aFiles) %>
<option value="<%=aFiles(i)%>"><%=aFiles(i)%></option>
<% Next %>


Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top