Hello,

I have a VB app that does this process in order:
1) Open a folder and for each file, delete the last 3 lines
2) Use the commondialog control to open a file in the same folder
3) Extract pertinent information from that file (the location of each extracted string is in the same place every time)
4) API usage: import the file into a specialized database

How would you automate this process so that in step 1 & 2, I won't have to choose a folder and file manually, it'll extract all the info I need for every file in the folder? The way I was thinking this app would run is if it monitors a folder periodically and if it notices that more files got added into it,
run the above process.

Also, how would you make this app like a service or something that starts up when Windows does?

Here's my code:

VB Code:
  1. Option Explicit
  2.  
  3. '** For step 4 **
  4. 'Step 4 API usage
  5. Public LFAPI As LFAPI32COMLib.LFAPI32
  6.  
  7. '** For step 1 **
  8. 'Opens a treeview custom control to browse to a folder to convert .wma's
  9. Private sBuffer As String
  10.  
  11. Private Const BIF_RETURNONLYFSDIRS = 1
  12. Private Const BIF_DONTGOBELOWDOMAIN = 2
  13. Private Const MAX_PATH = 260
  14.  
  15. Private Declare Function SHBrowseForFolder Lib "shell32" _
  16.                                   (lpbi As BrowseInfo) As Long
  17.  
  18. Private Declare Function SHGetPathFromIDList Lib "shell32" _
  19.                                   (ByVal pidList As Long, _
  20.                                   ByVal lpBuffer As String) As Long
  21.  
  22. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
  23.                                   (ByVal lpString1 As String, ByVal _
  24.                                   lpString2 As String) As Long
  25.  
  26. Private Type BrowseInfo
  27.    hWndOwner      As Long
  28.    pIDLRoot       As Long
  29.    pszDisplayName As Long
  30.    lpszTitle      As Long
  31.    ulFlags        As Long
  32.    lpfnCallback   As Long
  33.    lParam         As Long
  34.    iImage         As Long
  35. End Type
  36.  
  37. 'End custom control
  38.  
  39. '** For step 1 **
  40. 'Deletes the last 3 lines of backuped .wma files so it can be read into VB
  41. Private Sub deleteLine(line As Integer, fileStr As String)
  42.  
  43.     Dim sLine As String
  44.     Dim sFile As String
  45.     Dim ff As Integer
  46.     ff = FreeFile
  47.  
  48.     Open fileStr For Input As #ff
  49.    
  50.     Dim lineNum As Integer
  51.     lineNum = 0
  52.    
  53.     While Not EOF(ff)
  54.        'in case you want to delete by line number
  55.        lineNum = lineNum + 1
  56.        Line Input #ff, sLine
  57.        
  58.        'just an example you could also see if strLine = the line you want to delete
  59.        If lineNum <> line Then
  60.            sFile = sFile & sLine & vbCrLf
  61.        End If
  62.        
  63.     Wend
  64.    
  65.     Close (ff)
  66.     ff = FreeFile
  67.     Open fileStr For Output As #ff
  68.     Print #ff, sFile
  69.     Close (ff)
  70.  
  71. End Sub
  72.  
  73. '** For step 1 **
  74. 'Opens a Treeview control that displays the folders in a computer
  75. Private Sub cmdConvertFolder_Click()
  76.  
  77.     Dim lpIDList As Long
  78.     Dim szTitle As String
  79.     Dim response As Integer
  80.     Dim tBrowseInfo As BrowseInfo
  81.  
  82.     szTitle = "This is the title"
  83.     With tBrowseInfo
  84.        .hWndOwner = Me.hWnd
  85.        .lpszTitle = lstrcat(szTitle, "")
  86.        .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
  87.     End With
  88.  
  89.     'lpIDList = SHBrowseForFolder(tBrowseInfo) 'original place
  90.  
  91.     If (lpIDList) Then
  92.        sBuffer = Space(MAX_PATH)
  93.        SHGetPathFromIDList lpIDList, sBuffer
  94.        sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
  95.        'MsgBox sBuffer
  96.     End If
  97.    
  98.     response = MsgBox("Did you backup your .wma files? All .wma files in this folder will be converted!", vbExclamation + vbYesNoCancel, "ECS Importer")
  99.     If response = vbYes Then
  100.         lpIDList = SHBrowseForFolder(tBrowseInfo) 'moved to go w/ the vbYes response
  101.         OpenPath sBuffer, ".wma"
  102.     Else
  103.         'do nothing
  104.     End If
  105. End Sub
  106.  
  107. 'Part of the above sub
  108. Private Sub OpenPath(strPath As String, Optional extension As String)
  109.    'Leave Extension blank for all files
  110.    Dim File As String
  111.  
  112.    If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
  113.  
  114.    If Trim$(extension) = "" Then
  115.        extension = "*.*"
  116.    ElseIf Left$(extension, 2) <> "*." Then
  117.        extension = "*." & extension
  118.    End If
  119.  
  120.    File = Dir$(strPath & extension)
  121.    Do While Len(File)
  122.        deleteLine 3, File
  123.        File = Dir$
  124.    Loop
  125. End Sub
  126.  
  127. '** Step 2 & 3 **
  128. 'Opens commond dialog box to find which file you want to extract
  129. Private Sub cmdRead_Click()
  130.    
  131.     On Error Resume Next
  132.     Dim strFileLine As String
  133.     Dim strOfficer As String
  134.     Dim strDate As String
  135.     Dim strYear As String
  136.     Dim strMonth As String
  137.     Dim strDay As String
  138.     Dim strStartTime
  139.     Dim strEndTime
  140.     Dim strStartHour As String
  141.     Dim strStartMin As String
  142.     Dim strStartSec As String
  143.     Dim strEndHour As String
  144.     Dim strEndMin As String
  145.     Dim strEndSec As String
  146.    
  147.     With CommonDialog1
  148.         'raise an error if cancel was hit
  149.         .Filter = ".wma files (*.wma)|*.wma|" & "All files (*.*)|*.*"
  150.         .Flags = cdlOFNHideReadOnly
  151.         .CancelError = True
  152.         .ShowOpen
  153.        
  154.         ' 32755 is the cancel error raised
  155.         If Err.Number = 32755 Then
  156.             Exit Sub
  157.         Else
  158.             Open CommonDialog1.FileName For Input As #1
  159.             Line Input #1, strFileLine 'All the information in the .wma file ready to extract
  160.             Close #1
  161.         End If
  162.     End With
  163.    
  164.     txtDoc.Text = CommonDialog1.FileTitle
  165.    
  166.     txtOfficer.Text = Mid(strFileLine, 56, 4)
  167.     strDate = Mid(strFileLine, 79, 6)
  168.    
  169.     strMonth = Mid(strDate, 3, 2)
  170.     strDay = Mid(strDate, 5, 2)
  171.     strYear = Mid(strDate, 1, 2)
  172.    
  173.     txtDate.Text = strMonth & "/" & strDay & "/" & strYear
  174.    
  175.     strStartHour = Mid(strFileLine, 85, 2)
  176.     strStartMin = Mid(strFileLine, 87, 2)
  177.     strStartSec = Mid(strFileLine, 89, 2)
  178.    
  179.     strEndHour = Mid(strFileLine, 97, 2)
  180.     strEndMin = Mid(strFileLine, 99, 2)
  181.     strEndSec = Mid(strFileLine, 101, 2)
  182.  
  183.     txtStartTime.Text = strStartHour & ":" & strStartMin & ":" & strStartSec
  184.     txtEndTime.Text = strEndHour & ":" & strEndMin & ":" & strEndSec
  185.  
  186. End Sub
  187.  
  188. '** Step 4 **
  189. 'Inserts the info into LF
  190. Private Sub cmdInsert_Click()
  191.     Set LFAPI = New LFAPI32COMLib.LFAPI32
  192.    
  193.     Dim strCreateDoc As String
  194.     Dim strImport As String
  195.    
  196.     LFAPI.LoginEx "ECS Demo 6", "admin", "admin"
  197.     LFAPI.CreateFolder "WMA", "ECS Demo 6"
  198.    
  199.     strImport = LFAPI.ImportElectronicFile _
  200.     (CommonDialog1.FileName, "ECS Demo 6\WMA", txtDoc.Text, , , "WMA")
  201.    
  202.     LFAPI.SetFieldValue "ECS Demo 6\WMA\" & txtDoc.Text, "Officer", txtOfficer.Text
  203.     LFAPI.SetFieldValue "ECS Demo 6\WMA\" & txtDoc.Text, "Date", txtDate.Text
  204.     LFAPI.SetFieldValue "ECS Demo 6\WMA\" & txtDoc.Text, "Start Time", txtStartTime.Text
  205.     LFAPI.SetFieldValue "ECS Demo 6\WMA\" & txtDoc.Text, "End Time", txtEndTime.Text
  206.        
  207.     LFAPI.Logout
  208.    
  209.     MsgBox "Document successfully created in LaserFiche.", vbInformation, "ECS Importer"
  210. End Sub

Thanks!

Chris