VB Code:
  1. 'This project needs a Common Dialog box, named CDBox.
  2. '  (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
  3. '   and select Microsoft Common Dialog control)
  4. Private Type FILETIME
  5.     dwLowDateTime As Long
  6.     dwHighDateTime As Long
  7. End Type
  8.     Private Type SYSTEMTIME
  9.     wYear As Integer
  10.     wMonth As Integer
  11.     wDayOfWeek As Integer
  12.     wDay As Integer
  13.     wHour As Integer
  14.     wMinute As Integer
  15.     wSecond As Integer
  16.     wMilliseconds As Integer
  17. End Type
  18. Private Const GENERIC_WRITE = &H40000000
  19. Private Const OPEN_EXISTING = 3
  20. Private Const FILE_SHARE_READ = &H1
  21. Private Const FILE_SHARE_WRITE = &H2
  22. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  23. Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
  24. Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
  25. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  26. Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
  27.  
  28. Private Sub Form_Load()
  29.  
  30.     Dim m_Date As Date, lngHandle As Long
  31.     Dim udtFileTime As FILETIME
  32.     Dim udtLocalTime As FILETIME
  33.     Dim udtSystemTime As SYSTEMTIME
  34.     m_Date = Format(Now, "DD-MM-YY")
  35.  
  36.     'Set the dialog's title
  37.     CDBox.DialogTitle = "Choose a file ..."
  38.     'Set the dialog's filter
  39.     CDBox.Filter = "All Files (*.*)|*.*"
  40.     'Show the 'Open File'-dialog
  41.     CDBox.ShowOpen
  42.  
  43.     udtSystemTime.wYear = Year(m_Date)
  44.     udtSystemTime.wMonth = Month(m_Date)
  45.     udtSystemTime.wDay = Day(m_Date)
  46.     udtSystemTime.wDayOfWeek = WeekDay(m_Date) - 1
  47.     udtSystemTime.wHour = Hour(m_Date)
  48.     udtSystemTime.wMinute = Minute(m_Date)
  49.     udtSystemTime.wSecond = Second(m_Date)
  50.     udtSystemTime.wMilliseconds = 0
  51.  
  52.     ' convert system time to local time
  53.     SystemTimeToFileTime udtSystemTime, udtLocalTime
  54.     ' convert local time to GMT
  55.     LocalFileTimeToFileTime udtLocalTime, udtFileTime
  56.     ' open the file to get the filehandle
  57.     lngHandle = CreateFile(CDBox.Filename, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
  58.     ' change date/time property of the file
  59.     SetFileTime lngHandle, udtFileTime, udtFileTime, udtFileTime
  60.     ' close the handle
  61.     CloseHandle lngHandle
  62.     MsgBox "The date of the file '" + CDBox.Filename + "' has been changed to" + Str$(m_Date), vbInformation + vbOKOnly, App.Title
  63. End Sub