i'm trying to build a picture database , i want vb to track a specified folder so when u add new pictures to that folder it will automaticly add it to the database. is that possible in vb6?
thanx.
Printable View
i'm trying to build a picture database , i want vb to track a specified folder so when u add new pictures to that folder it will automaticly add it to the database. is that possible in vb6?
thanx.
Welcome to VB Forums :)
There are two possible ways i can think of... one is to have a timer every minute to check the folder for any changes. The other is to use an API. The timer method could possibly use the filelistbox control, and then every minute check the total number of items, if its different then it means something was added or removed. The API method would be something like this (from the API Guide)
But this will pause your program until it finds a change.VB Code:
Private Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4 Private Const FILE_NOTIFY_CHANGE_DIR_NAME = &H2 Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1 Private Const FILE_NOTIFY_CHANGE_SIZE = &H8 Private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10 Private Const FILE_NOTIFY_CHANGE_SECURITY = &H100 Private Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1 Or &H8 Or &H10 Or &H100 Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long Private Declare Function FindNextChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function ResetEvent Lib "kernel32" (ByVal hEvent As Long) As Long Private Sub Form_Load() 'KPD-Team 2000 'URL: [url]http://www.allapi.net/[/url] 'E-Mail: [email][email protected][/email] Dim Ret As Long 'Set the notification hook Ret = FindFirstChangeNotification("C:\", &HFFFFFFFF, FILE_NOTIFY_CHANGE_ALL) 'Wait until the event is triggered WaitForSingleObject Ret, &HFFFFFFFF MsgBox "Event Triggered for the first time" 'Reactivate our hook FindNextChangeNotification Ret 'Wait until the event is triggered WaitForSingleObject Ret, &HFFFFFFFF MsgBox "Event Triggered for the second time" 'Remove our hook FindCloseChangeNotification Ret End Sub
thank you for reply,
i think i'm going to try timer first but i cannot find filelistbox control in the component or Refrences. can you help where i can get that control from plz.
its in the VB controls... its icon is white with lines on it (it looks like a textfile)
Just a quick example on how you might use it
VB Code:
Private Sub Form_Load() File1.Path = "C:\" Timer1.Interval = 60000 End Sub Private Sub Timer1_Timer() Static PrevListCount As Long File1.Refresh If File1.ListCount <> PrevListCount Then 'go through all the files to check what was added PrevListCount = File1.ListCount End If End Sub
thank you very much, i think its clear to me now. :wave: :thumb:
hi again, i made a little progress now, i want to group some pictures in folders. is there any control allow me to track folders creation? actualy i have too much folders with images so i decided to make the program to group my pictures by folder name.
thank you.
You can use a ImageListBox inside your program.
Select ProjectMenu-->Components-->MicrosoftComponets Control
Or the DirListBox, its the control next to the FileListBox (its got the icon of the folder)
thank you guys. :wave: :thumb: