Results 1 to 2 of 2

Thread: [RESOLVED] watch teh folder and print any file the is saved

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Location
    In the midst of corn, cotton, and beans
    Posts
    185

    Resolved [RESOLVED] watch teh folder and print any file the is saved

    Sometimes it is very quick to print the file, and sometimes there is like a 5-7 second delay.
    the file is printed on line 61 through a third party app.

    Any suggestions are very appreciated

    vb Code:
    1. Option Explicit
    2. Dim DelFiles(0 To 100) As String
    3. Dim FS As New FileSystemObject
    4. Dim FSfolder As Folder
    5. Dim File As File
    6. Dim Cmd As String
    7. Dim ErrCnt As Integer
    8. Dim strStartPath As String
    9.  
    10. Private Sub CmdRprint_Click()
    11.     Dim TNum As String
    12.     Dim dFil As String
    13.     Dim Highest As Currency
    14.     Dim sFileName As String
    15.     TNum = InputBox("Enter the six digit Invoice Number:", "Re-Print Ticket")
    16.     dFil = "c:\invprnt\" & TNum & ".txt"
    17.     TNum = "c:\bkupinv\" & TNum & ".txt"
    18.     If MRpt.CheckFileExist(TNum) = True Then
    19.         Call FileCopy(TNum, dFil)
    20.         Kill TNum
    21.     ElseIf TNum = "c:\bkupinv\747.txt" Then
    22.         Call Form_Load
    23.     ElseIf TNum = "c:\bkupinv\00.txt" Then
    24.         sFileName = Dir$("c:\bkupinv\" & "*.txt", vbNormal)
    25.         Do Until sFileName = ""
    26.             If Val(sFileName) > Highest Then
    27.                 Highest = Val(sFileName)
    28.             End If
    29.             sFileName = Dir
    30.         Loop
    31.         Debug.Print "highest number file name = " & Highest & ".txt"
    32.         Call FileCopy("c:\bkupinv\" & Highest & ".txt", "c:\invprnt\" & Highest & ".txt")
    33.     Else
    34.         MsgBox "Invalid invoice number.", vbOKOnly, "Entry error"
    35.     End If
    36. End Sub
    37.  
    38. Private Sub Form_Load()
    39.     Dim ClkInt As Long
    40.     ClkInt = CLng(basRegistry.regQuery_A_Key(HKEY_LOCAL_MACHINE, "SOFTWARE", "PRNTMONITOR"))
    41.     StrtTime.Interval = ClkInt
    42.     Timer.Interval = ClkInt
    43.     StrtTime.Enabled = False
    44.     Timer.Enabled = False
    45.     strStartPath = "C:\invprnt"
    46.     Cmd = "c:\dosprint\dosprinter /raw "
    47.     Set FSfolder = FS.GetFolder(strStartPath)
    48.     Call ListFolder(strStartPath)
    49. End Sub
    50.  
    51. Private Sub ListFolder(sFolderPath As String)
    52.     Dim Cnt As Integer
    53.     On Error GoTo ErrorHandle
    54.     Cnt = 0
    55.     StrtTime.Enabled = False
    56.     Timer.Enabled = False
    57.         Text1.Text = ""
    58.         For Each File In FSfolder.Files
    59.             DoEvents
    60.             Text1.Text = Text1.Text & File & vbCrLf
    61.             Shell (Cmd & File)
    62.             DelFiles(Cnt) = File
    63.             Cnt = Cnt + 1
    64.         Next File
    65.     Timer.Enabled = True
    66.     Exit Sub
    67. ErrorHandle:
    68.     ErrCnt = ErrCnt + 1
    69.     If ErrCnt < 2 Then
    70.         Call ListFolder(strStartPath)
    71.     Else
    72.         Call MsgBox(Error & vbCrLf & "ListFolder")
    73.     End If
    74. End Sub
    75.  
    76. Private Sub StrtTime_Timer()
    77.     Timer.Enabled = False
    78.     On Error GoTo ErrorHandle
    79.     StrtTime.Enabled = False
    80.     Call ListFolder("c:\invprnt")
    81.     Exit Sub
    82. ErrorHandle:
    83.     MsgBox (Error & vbCrLf & "StrtTime")
    84. End Sub
    85.  
    86. Private Sub Timer_Timer()
    87.     Dim Flag As Boolean
    88.     Dim Cnt As Integer
    89.     On Error GoTo ErrorHandle
    90.     ErrCnt = 0
    91.     StrtTime.Enabled = False
    92.     Timer.Enabled = False
    93.     Flag = True
    94.     Cnt = 0
    95.     Do While Flag = True And Cnt < 101
    96.         If IsNull(DelFiles(Cnt)) = True Or DelFiles(Cnt) = "" Then
    97.             Flag = False
    98.         Else
    99.             Call FileCopy(DelFiles(Cnt), "c:\bkupinv\" & Right(DelFiles(Cnt), 10))
    100.             Call Kill(DelFiles(Cnt))
    101.             Cnt = Cnt + 1
    102.         End If
    103.     Loop
    104.     Cnt = Cnt - 1
    105.     Do While Cnt >= 0
    106.         DelFiles(Cnt) = ""
    107.         Cnt = Cnt - 1
    108.     Loop
    109.     StrtTime.Enabled = True
    110.     Exit Sub
    111. ErrorHandle:
    112.     MsgBox (Error & vbCrLf & "Timer")
    113. End Sub

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Location
    In the midst of corn, cotton, and beans
    Posts
    185

    Re: watch teh folder and print any file the is saved

    I modified the code a little.
    I was able to drop one Sub entirely.

    the print command is now found on line 58

    vb Code:
    1. Option Explicit
    2. Dim DelFiles(0 To 100) As String
    3. Dim FS As New FileSystemObject
    4. Dim FSfolder As Folder
    5. Dim File As File
    6. Dim Cmd As String
    7. Dim ErrCnt As Integer
    8. Dim strStartPath As String
    9.  
    10. Private Sub CmdRprint_Click()
    11.     Dim TNum As String
    12.     Dim dFil As String
    13.     Dim Highest As Currency
    14.     Dim sFileName As String
    15.     TNum = InputBox("Enter the six digit Invoice Number:", "Re-Print Ticket")
    16.     dFil = "c:\invprnt\" & TNum & ".txt"
    17.     TNum = "c:\bkupinv\" & TNum & ".txt"
    18.     If MRpt.CheckFileExist(TNum) = True Then
    19.         Call FileCopy(TNum, dFil)
    20.         Kill TNum
    21.     ElseIf TNum = "c:\bkupinv\747.txt" Then
    22.         Call Form_Load
    23.     ElseIf TNum = "c:\bkupinv\00.txt" Then
    24.         sFileName = Dir$("c:\bkupinv\" & "*.txt", vbNormal)
    25.         Do Until sFileName = ""
    26.             If Val(sFileName) > Highest Then
    27.                 Highest = Val(sFileName)
    28.             End If
    29.             sFileName = Dir
    30.         Loop
    31.         Debug.Print "highest number file name = " & Highest & ".txt"
    32.         Call FileCopy("c:\bkupinv\" & Highest & ".txt", "c:\invprnt\" & Highest & ".txt")
    33.     Else
    34.         MsgBox "Invalid invoice number.", vbOKOnly, "Entry error"
    35.     End If
    36. End Sub
    37.  
    38. Private Sub Form_Load()
    39.     Dim ClkInt As Long
    40.     ClkInt = CLng(basRegistry.regQuery_A_Key(HKEY_LOCAL_MACHINE, "SOFTWARE", "PRNTMONITOR"))
    41.     Timer.Interval = ClkInt
    42.     Timer.Enabled = False
    43.     strStartPath = "C:\invprnt"
    44.     Cmd = "c:\dosprint\dosprinter /raw "
    45.     Set FSfolder = FS.GetFolder(strStartPath)
    46.     Call ListFolder(strStartPath)
    47. End Sub
    48.  
    49. Private Sub ListFolder(sFolderPath As String)
    50.     Dim Cnt As Integer
    51.     On Error GoTo ErrorHandle
    52.     Cnt = 0
    53.     Timer.Enabled = False
    54.         Text1.Text = ""
    55.         For Each File In FSfolder.Files
    56.             DoEvents
    57.             Text1.Text = Text1.Text & File & vbCrLf
    58.             Shell (Cmd & File)
    59.             DelFiles(Cnt) = File
    60.             Cnt = Cnt + 1
    61.         Next File
    62.     Timer.Enabled = True
    63.     Exit Sub
    64. ErrorHandle:
    65.     ErrCnt = ErrCnt + 1
    66.     If ErrCnt < 2 Then
    67.         Call ListFolder(strStartPath)
    68.     Else
    69.         Call MsgBox(Error & vbCrLf & "ListFolder")
    70.     End If
    71. End Sub
    72.  
    73. Private Sub Timer_Timer()
    74.     Dim Flag As Boolean
    75.     Dim Cnt As Integer
    76.     On Error GoTo ErrorHandle
    77.     ErrCnt = 0
    78.     Timer.Enabled = False
    79.     Flag = True
    80.     Cnt = 0
    81.     Do While Flag = True And Cnt < 101
    82.         If IsNull(DelFiles(Cnt)) = True Or DelFiles(Cnt) = "" Then
    83.             Flag = False
    84.         Else
    85.             Call FileCopy(DelFiles(Cnt), "c:\bkupinv\" & Right(DelFiles(Cnt), 10))
    86.             Call Kill(DelFiles(Cnt))
    87.             Cnt = Cnt + 1
    88.         End If
    89.     Loop
    90.     Cnt = Cnt - 1
    91.     Do While Cnt >= 0
    92.         DelFiles(Cnt) = ""
    93.         Cnt = Cnt - 1
    94.     Loop
    95.     Call ListFolder("c:\invprnt")
    96.     Timer.Enabled = True
    97.     Exit Sub
    98. ErrorHandle:
    99.     MsgBox (Error & vbCrLf & "Timer")
    100. End Sub


    _____________________________________________________________

    resolved
    http://www.vbforums.com/showthread.php?t=560936

    the above link is what I ended up with
    Last edited by re_turner_jr; Jul 29th, 2009 at 08:33 AM. Reason: marking thread as resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width