Hmmm; det var ikke ret mange points... Nå, skidt: Hvis du har en combobox, der hedder Combo, og en Commandbutton, der hedder 'Go', så gør flg. kode det ønskede. I variablen sDir skal du have stien til det bibliotek, som skal vises, afsluttet med backslash (ie. "C:\billeder\"). Du kan sikkert godt regne ud, hvordan du tilføjer / ændrer extensions, der skal vises:
Dim sDir As String Dim Ext(10) As String Dim I As Integer, Z As Integer Dim A As Boolean
Private Sub Form_Load() Ext(0) = "*.jpg" Ext(1) = "*.bmp"
End Sub
Private Sub Go_Click() sDir = sDir + "\"
For I = 0 To 10 A = GetFiles(sDir, Ext(I)) For Z = 0 To CountFiles Combo.AddItem (Files(Z)) Next Z If Ext(I + 1) = "" Then Exit For Next I
End Sub
Flg. kommentar skal lige kopieres over i et modul:
Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * 260 cAlternate As String * 14 End Type Option Explicit
Public Type BrowseInfo hwndOwner As Long pIDLRoot As Long pszDisplayName As Long lpszTitle As Long ulFlags As Long lpfnCallback As Long lParam As Long iImage As Long End Type
Public Const BIF_RETURNONLYFSDIRS = 1 Public Const MAX_PATH = 260
Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long) Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" _ (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" _ (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long Declare Function FindClose Lib "kernel32.dll" (ByVal hFindFile As Long) As Long Declare Function SetFileAttributes Lib "kernel32.dll" Alias "SetFileAttributesA" _ (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long Dim FileInfo As WIN32_FIND_DATA Dim hFile As Long Dim Res As Long Public Const NormAtt = &H80 Public Const OFN_HIDEREADONLY = &H4 Public Const OFN_OVERWRITEPROMPT = &H2 Public Const OFN_PATHMUSTEXIST = &H800 Public Const IllegalChars As String = "\/:*?<>|" Public Illegal(255) As String Public CountFiles As Long Public Files(10000) As String
Public Function GetFiles(Dir As String, Pattern As String) As Boolean Erase Files CountFiles = 0
hFile = FindFirstFile(Dir + Pattern, FileInfo)
If hFile = -1 Then GetFiles = False Exit Function End If
If Not FileInfo.dwFileAttributes = &H10 And Not Left(FileInfo.cFileName, 8) = "Recycled" Then Files(CountFiles) = FileInfo.cFileName Files(CountFiles) = Left$(Files(CountFiles), InStr(1, Files(CountFiles), vbNullChar) - 1) Else CountFiles = -1 End If
Do Res = FindNextFile(hFile, FileInfo) If Res = 0 Then Exit Do Else If Not FileInfo.dwFileAttributes = &H10 And Not Left(FileInfo.cFileName, 8) = "Recycled" Then CountFiles = CountFiles + 1 Files(CountFiles) = FileInfo.cFileName Files(CountFiles) = Left$(Files(CountFiles), InStr(1, Files(CountFiles), vbNullChar) - 1) Res = SetFileAttributes(Dir + Files(CountFiles), NormAtt) End If End If Loop
'sDirectory er mappen du vil vise filerne i, og her er jeg gået ud fra at navnet på din combobox er cmbFiles Dim sDirectory As String, oFSO As Object, oFile As Object, oFolder As Object, sCurFilename As String, sFileParts() As String sDirectory = "C:\" Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder(sDirectory) For Each oFile In oFolder.Files If InStr(1, oFile.Name, ".") <> 0 Then sFileParts() = Split(oFile.Name, ".") If LCase(sFileParts(UBound(sFileParts()))) = "jpg" Or _ LCase(sFileParts(UBound(sFileParts()))) = "jpge" Or _ LCase(sFileParts(UBound(sFileParts()))) = "gif" Or _ LCase(sFileParts(UBound(sFileParts()))) = "bmp" Then cmbFiles.AddItem oFile.Name End If Next oFile -------------------------------------------------------- Ja, sådan kan det jo også gøres :)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.