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