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!

Scanning pic files

Status
Not open for further replies.

dominiopt

Technical User
Sep 10, 2001
75
0
0
PT
How can i restrict the following code to jpg, gif and bmp files ?

Dim Files$
Files = Dir(App.Path & "\*.*")
Do Until Len(Files) = 0
If MsgBox(Files, vbOKCancel) = vbCancel Then
Exit Do
End If
Files = Dir
Loop

Thanks
Fernando
 
Since you have only a few extensions, I would probably imbed the check into the code like:

Files = Dir(App.Path & "\*.*")
Do Until Len(Files) = 0
FileName = LCase(Files)
If InStr(1, FileName, ".bmp") > 0 _
Or InStr(1, FileName, ".gif") > 0 _
Or InStr(1, FileName, ".jpg") > 0 Then
If MsgBox(Files, vbOKCancel) = vbCancel Then
Exit Do
End If
End If
Files = Dir
Loop


This is not a very elegant solution. For something more dynamic, you could maintain an array or a listbox of extensions you want to select then write a function to check whether the filename passes this filter.
 
Thanks Kmomberg, just in case ... i did found this way out

Filename = Dir(App.Path & "\*.*")
Do Until Len(Filename) = 0
'get file extension
For n = Len(Filename) To (Len(Filename) - 2) Step -1
ext = Mid(Filename, n, 3)
Next n
Dir=Filename
msgbox (ext)
Loop

Fernando
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top