[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:
Option Explicit
Dim DelFiles(0 To 100) As String
Dim FS As New FileSystemObject
Dim FSfolder As Folder
Dim File As File
Dim Cmd As String
Dim ErrCnt As Integer
Dim strStartPath As String
Private Sub CmdRprint_Click()
Dim TNum As String
Dim dFil As String
Dim Highest As Currency
Dim sFileName As String
TNum = InputBox("Enter the six digit Invoice Number:", "Re-Print Ticket")
dFil = "c:\invprnt\" & TNum & ".txt"
TNum = "c:\bkupinv\" & TNum & ".txt"
If MRpt.CheckFileExist(TNum) = True Then
Call FileCopy(TNum, dFil)
Kill TNum
ElseIf TNum = "c:\bkupinv\747.txt" Then
Call Form_Load
ElseIf TNum = "c:\bkupinv\00.txt" Then
sFileName = Dir$("c:\bkupinv\" & "*.txt", vbNormal)
Do Until sFileName = ""
If Val(sFileName) > Highest Then
Highest = Val(sFileName)
End If
sFileName = Dir
Loop
Debug.Print "highest number file name = " & Highest & ".txt"
Call FileCopy("c:\bkupinv\" & Highest & ".txt", "c:\invprnt\" & Highest & ".txt")
Else
MsgBox "Invalid invoice number.", vbOKOnly, "Entry error"
End If
End Sub
Private Sub Form_Load()
Dim ClkInt As Long
ClkInt = CLng(basRegistry.regQuery_A_Key(HKEY_LOCAL_MACHINE, "SOFTWARE", "PRNTMONITOR"))
StrtTime.Interval = ClkInt
Timer.Interval = ClkInt
StrtTime.Enabled = False
Timer.Enabled = False
strStartPath = "C:\invprnt"
Cmd = "c:\dosprint\dosprinter /raw "
Set FSfolder = FS.GetFolder(strStartPath)
Call ListFolder(strStartPath)
End Sub
Private Sub ListFolder(sFolderPath As String)
Dim Cnt As Integer
On Error GoTo ErrorHandle
Cnt = 0
StrtTime.Enabled = False
Timer.Enabled = False
Text1.Text = ""
For Each File In FSfolder.Files
DoEvents
Text1.Text = Text1.Text & File & vbCrLf
Shell (Cmd & File)
DelFiles(Cnt) = File
Cnt = Cnt + 1
Next File
Timer.Enabled = True
Exit Sub
ErrorHandle:
ErrCnt = ErrCnt + 1
If ErrCnt < 2 Then
Call ListFolder(strStartPath)
Else
Call MsgBox(Error & vbCrLf & "ListFolder")
End If
End Sub
Private Sub StrtTime_Timer()
Timer.Enabled = False
On Error GoTo ErrorHandle
StrtTime.Enabled = False
Call ListFolder("c:\invprnt")
Exit Sub
ErrorHandle:
MsgBox (Error & vbCrLf & "StrtTime")
End Sub
Private Sub Timer_Timer()
Dim Flag As Boolean
Dim Cnt As Integer
On Error GoTo ErrorHandle
ErrCnt = 0
StrtTime.Enabled = False
Timer.Enabled = False
Flag = True
Cnt = 0
Do While Flag = True And Cnt < 101
If IsNull(DelFiles(Cnt)) = True Or DelFiles(Cnt) = "" Then
Flag = False
Else
Call FileCopy(DelFiles(Cnt), "c:\bkupinv\" & Right(DelFiles(Cnt), 10))
Call Kill(DelFiles(Cnt))
Cnt = Cnt + 1
End If
Loop
Cnt = Cnt - 1
Do While Cnt >= 0
DelFiles(Cnt) = ""
Cnt = Cnt - 1
Loop
StrtTime.Enabled = True
Exit Sub
ErrorHandle:
MsgBox (Error & vbCrLf & "Timer")
End Sub
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:
Option Explicit
Dim DelFiles(0 To 100) As String
Dim FS As New FileSystemObject
Dim FSfolder As Folder
Dim File As File
Dim Cmd As String
Dim ErrCnt As Integer
Dim strStartPath As String
Private Sub CmdRprint_Click()
Dim TNum As String
Dim dFil As String
Dim Highest As Currency
Dim sFileName As String
TNum = InputBox("Enter the six digit Invoice Number:", "Re-Print Ticket")
dFil = "c:\invprnt\" & TNum & ".txt"
TNum = "c:\bkupinv\" & TNum & ".txt"
If MRpt.CheckFileExist(TNum) = True Then
Call FileCopy(TNum, dFil)
Kill TNum
ElseIf TNum = "c:\bkupinv\747.txt" Then
Call Form_Load
ElseIf TNum = "c:\bkupinv\00.txt" Then
sFileName = Dir$("c:\bkupinv\" & "*.txt", vbNormal)
Do Until sFileName = ""
If Val(sFileName) > Highest Then
Highest = Val(sFileName)
End If
sFileName = Dir
Loop
Debug.Print "highest number file name = " & Highest & ".txt"
Call FileCopy("c:\bkupinv\" & Highest & ".txt", "c:\invprnt\" & Highest & ".txt")
Else
MsgBox "Invalid invoice number.", vbOKOnly, "Entry error"
End If
End Sub
Private Sub Form_Load()
Dim ClkInt As Long
ClkInt = CLng(basRegistry.regQuery_A_Key(HKEY_LOCAL_MACHINE, "SOFTWARE", "PRNTMONITOR"))
Timer.Interval = ClkInt
Timer.Enabled = False
strStartPath = "C:\invprnt"
Cmd = "c:\dosprint\dosprinter /raw "
Set FSfolder = FS.GetFolder(strStartPath)
Call ListFolder(strStartPath)
End Sub
Private Sub ListFolder(sFolderPath As String)
Dim Cnt As Integer
On Error GoTo ErrorHandle
Cnt = 0
Timer.Enabled = False
Text1.Text = ""
For Each File In FSfolder.Files
DoEvents
Text1.Text = Text1.Text & File & vbCrLf
Shell (Cmd & File)
DelFiles(Cnt) = File
Cnt = Cnt + 1
Next File
Timer.Enabled = True
Exit Sub
ErrorHandle:
ErrCnt = ErrCnt + 1
If ErrCnt < 2 Then
Call ListFolder(strStartPath)
Else
Call MsgBox(Error & vbCrLf & "ListFolder")
End If
End Sub
Private Sub Timer_Timer()
Dim Flag As Boolean
Dim Cnt As Integer
On Error GoTo ErrorHandle
ErrCnt = 0
Timer.Enabled = False
Flag = True
Cnt = 0
Do While Flag = True And Cnt < 101
If IsNull(DelFiles(Cnt)) = True Or DelFiles(Cnt) = "" Then
Flag = False
Else
Call FileCopy(DelFiles(Cnt), "c:\bkupinv\" & Right(DelFiles(Cnt), 10))
Call Kill(DelFiles(Cnt))
Cnt = Cnt + 1
End If
Loop
Cnt = Cnt - 1
Do While Cnt >= 0
DelFiles(Cnt) = ""
Cnt = Cnt - 1
Loop
Call ListFolder("c:\invprnt")
Timer.Enabled = True
Exit Sub
ErrorHandle:
MsgBox (Error & vbCrLf & "Timer")
End Sub
_____________________________________________________________
resolved
http://www.vbforums.com/showthread.php?t=560936
the above link is what I ended up with