getting file names in a given directory and then storing them in an array (1 Viewer)

Trees

Registered User.
Local time
Today, 01:19
Joined
Jul 15, 2005
Messages
13
i Am new at VBA and i have a basic understanding.
I am trying to find out if it is possible to write code that would reffer to a given lcoation and store the file names in that location into an array.

i am planning on using the names in the array to populate a combo box. and then use the selected file name in the combobox (which would be a picture) to change the back ground of a form.

i can do the background part, thats easy.What i dont know how to do or if it could be done is to get the file names and store them into an array and then populate the combobox.

im not sure if arrays have to be defined in size that may be an issue because the number of pictures in the file would or could change. :confused:

all inupt would be greatly appreaceated

and please dont hate me for programming something so superficial :)
 

mikebaldam

Registered User.
Local time
Today, 01:19
Joined
Oct 29, 2002
Messages
114
Hi... I'm having a problem just storing the filename without the path.


I was told to see how these worked...
Try this one

But I'm still stuck.... may help you out though...?

Mike :confused:
 

Trees

Registered User.
Local time
Today, 01:19
Joined
Jul 15, 2005
Messages
13
what does the path you have look like i have an idea as to how you could get the file name
 

ghudson

Registered User.
Local time
Yesterday, 20:19
Joined
Jun 8, 2002
Messages
6,195
Try this...

Code:
Public Function ParseFileName(sFile As String) As String
On Error GoTo Err_ParseFileName

    Dim sPath As String
    
    sPath = sFile
    
    Do While Right$(sPath, 1) <> "\"
    sPath = Left$(sPath, Len(sPath) - 1)
    Loop
    
    ParseFileName = Mid$(sFile, Len(sPath) + 1)
 
Exit_ParseFileName:
    Exit Function

Err_ParseFileName:
    MsgBox Err.Number & " -" & Err.Description
    Resume Exit_ParseFileName
 
End Function
 

Users who are viewing this thread

Top Bottom