Advertisement
2002VB Windows API Call/ Explanation #18722

CreateDirX

This code will search the user's C:\ (or any other specified) drive for a given folder and if the folder is not found, it will call the CreateDirX function which in turn calls the API CreateDirectory function to create the specified folder. Once this is created, it will create a new notepad file within the folder and on each subsequent running of the application it will append info to this file. Great for logfile requirements!!

AI

Podsumowanie AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kod źródłowy
original-source
'include a common dialog control on your form for this baby to work
Public Sub OpenLog()
Dim LogFile as integer 
On Error GoTo exit1
 OpenLog.Flags = cdlOFNHideReadOnly Or cdlOFNExplorer
 OpenLog.CancelError = True
 OpenLog.FileName = "C:\JetLog\JET_LOG.log"  ' or whatever name grabs you by                       ' the nads
 temp = OpenLog.FileName
 Ret = Len(Dir$(temp))
 LogFile = FreeFile
 ' Open the log file.
 Open temp For Binary Access Write As LogFile
 If Err Then
  Exit Sub
 Else
  ' Go to the end of the file so that new data can be appended.
  Seek LogFile, LOF(LogFile) + 1
 End If
 Exit Sub
exit1:  ' Executes if folder is not found
 MsgBox "Application will create new directory 'C:\JetLog' on your hard drive." & vbCrLf & "Replace message with your own text.", vbExclamation, "Message"
 CreateDirX ("C:\JetLog")  'pass the path name you want to create in              ' these brackets
 OpenLog_Click
End Sub
Private Function CreateDirX(lpPathname As String) As Long
 Dim FYL As Long
 Dim DirC As SECURITY_ATTRIBUTES
  FYL = CreateDirectory(lpPathname, DirC)
End Function
Oryginalne komentarze (3)
Odzyskane z Wayback Machine