|
-
Mar 9th, 2009, 09:02 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Slow, sporadic print
OK, The app. is loaded on an XP network, with a shared USB OkiData dot matrix printer as the default printer on all PC's.
My app. simply monitors a certain folder, when a file is saved to that folder the app prints the file (via a third party application) and moves the file to another folder. Below is the code. On each PC there are two applications that are running.
There is a PointOfSale application - This is the app that writes files to the watched folder, this application is run in a Cmd window.
And the Print App - Below is the code
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 ErrCnt1 As Integer
Dim strStartPath As String
Dim ClkInt As Long
Dim LstTen(0 To 9) 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 I As Integer
ClkInt = CLng(basRegistry.regQuery_A_Key _
(HKEY_LOCAL_MACHINE, "SOFTWARE", "PRNTMONITOR"))
Timer.Interval = ClkInt
ListFolder.Interval = ClkInt
ListFolder.Enabled = False
Timer.Enabled = False
strStartPath = "C:\invprnt"
Cmd = "c:\dosprint\dosprinter /raw "
Set FSfolder = FS.GetFolder(strStartPath)
For I = 0 To 9
LstTen(I) = ""
Next
ListFolder.Enabled = True
End Sub
Private Sub ListFolder_Timer()
Dim Cnt As Integer
Dim I As Integer
On Error GoTo ErrorHandle
Timer.Enabled = False
ListFolder.Enabled = False
Cnt = 0
ErrCnt1 = 0
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
ListFolder.Enabled = True
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
ListFolder.Enabled = False
Timer.Enabled = False
ErrCnt = 0
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
ListFolder.Enabled = True
Exit Sub
ErrorHandle:
ErrCnt1 = ErrCnt1 + 1
If ErrCnt1 < 2 Then
Timer.Enabled = True
ListFolder.Enabled = False
Else
Timer.Enabled = False
ListFolder.Enabled = True
End If
End Sub
The problem is that sometimes (not all the time) the application does not print the file. It still move it to the other folder, but it is not send to the printer.
Also sporadically, the printer is very slow in printing the file, by slow I mean sometimes it takes 20 - 40 seconds.
Does anyone see anything that I can fix in the above code? I'm out of options on this and will soon have to try and find another solution, so any help is very much appreciated.
Thanks
-RT
-
Mar 9th, 2009, 11:57 AM
#2
Re: Slow, sporadic print
If it is sometimes but not all the times I would think your code is OK, otherwise, it would be causing a problem all the time.
Can you find any consistency in the times when it does not print? Are there high volumes of network traffic during these times? Is the print job actually being sent, but perhaps getting lost in the print queue (the printer you are using is not exactly new/state of the art.)?
-
Mar 9th, 2009, 12:17 PM
#3
Thread Starter
Addicted Member
Re: Slow, sporadic print
Hack- I have not seen any consistency in this problem. Network traffic is not the issue. The third party app, which actually sends the queue, might be the cause of the problem.
Is there any way that I can send the print job out of vb without using the third party app. The reason I chose to use the third party app is that I cannot send it in graphical mode, it needs to be in text mode. If I can do this with pure vb and cut out the other app then I think that would solve some of my problem, it would at least eliminate that from the list of things that could be causing my problem?
-
Mar 9th, 2009, 12:19 PM
#4
Re: Slow, sporadic print
Try using ShellExecute to print it and see what happens.
Something like
Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Sub Command1_Click()
ShellExecute Me.hwnd, "print", "c:\invprnt\" & TNum & ".txt", , "C:\", SW_SHOWNORMAL
End Sub
Last edited by Hack; Mar 9th, 2009 at 01:31 PM.
-
Mar 9th, 2009, 03:53 PM
#5
Re: Slow, sporadic print
is the oki installed on the network, with a tcp/ip address or just as a shared printer installed on a local computer
if it is on a pc any printing has to be done in turn with other stuff running on the host pc, as well as fitting in with network traffic
is your code running on the pc with the printer attached?
are you running your app on each pc, monitoring a local folder?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 9th, 2009, 04:36 PM
#6
Thread Starter
Addicted Member
Re: Slow, sporadic print
 Originally Posted by westconn1
is the oki installed on the network, with a tcp/ip address or just as a shared printer installed on a local computer
if it is on a pc any printing has to be done in turn with other stuff running on the host pc, as well as fitting in with network traffic
is your code running on the pc with the printer attached?
are you running your app on each pc, monitoring a local folder?
The Oki is installed on a PC and shared, it does not have an ip addy of it's own.
Yes, my code is running on the PC with the printer attached, as well as, the POS app mentioned in the OP.
Yes, each PC has my app running on it monitoring a local folder.
 Originally Posted by Hack
Try using ShellExecute to print it and see what happens.
I will give that a try tomorrow and post back, I had an unexpected company road trip today and ran out of time.
-RT
-
Mar 9th, 2009, 04:39 PM
#7
Hyperactive Member
Re: Slow, sporadic print
I have a lot of experience debugging problems like this.
First of all, the longer print times are most likely due to the printer occasionally needing to warm up. The printer at my old office used to stay warmed up for 30 minutes which if it received no other printing assignments during that time, it would shut down, and subsequent printing assignments would take much longer, just as you described.
Also, I noticed in your code that you are sending the document to the print queue on the line before you delete it. When a document is sent to the print queue it begins storing an image of the file in the printer's buffer. If the buffer is not able to be completed (like because the file is deleted too quickly), most printers automatically cancel the job.
How to confirm:
You should be noticing that much larger documents are less likely to actually get printed. Try adding a DoEvents between the printing and file moving statements, and you should notice the size of files that usually get printed will be noticeably larger.
I would add the code Hack suggested, followed by a considerable delay (at least 10 seconds) before moving the files. I'm not aware of a way to confirm your printer has finished buffering, but you can add enough of a delay that it becomes irrelevant.
Enjoy.
-
Mar 10th, 2009, 02:42 AM
#8
Re: Slow, sporadic print
First of all, the longer print times are most likely due to the printer occasionally needing to warm up
it is a oki dot matrix
Yes, each PC has my app running on it monitoring a local folder.
might be better to run your program only on the pc with the printer and to monitor the folders on the other computers as well as the folder on the local pc, or move the files over the network to that pc, then monitor there
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 10th, 2009, 08:42 AM
#9
Thread Starter
Addicted Member
Re: Slow, sporadic print
Hack - while ShellExecute does print it will not work for me, at lease not as is. The file that is being generated is from a program that was written for DOS and in the text/print file that is generated is the special characters that control the printer. This is why I need text mode rather that graphical. If I print using ShellExecute it prints all of the control characters (boxes, W0, P, F, etc...)
This is why I decided to use the third party app, it interprets the control characters prints accordingly.
deathfxu - all of the files are relatively small and the same size. Also, as stated by west, I am using a dot matrix printer and they don't have a fuser and don't need to warm up.
westconn1 - monitoring remote folders or moving the files to a central loc. is not a very good option for the current setup of the network. I tend to agree with you though, it would eliminate one more thing. but none the less, in the company for which I work this solution is nothing more than wishful thinking and pipe dreams.
-
Mar 10th, 2009, 09:41 AM
#10
Thread Starter
Addicted Member
Re: Slow, sporadic print
If it helps any, the following is the output from the POS, this is what gets sent to the printer. This in not what it looks like when actually printed. The ~~~ are placed by me
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PE
1107 Highway 49
Marvell, Arkansas 78766
501-829-2786
M
Look Up Account Date: 5/28/08 9:05AM
Inv : W1667821 W0
Cust: W100000W0
By : RT
PF
Stock No. Qty. UM Description Price Extended
123 1 EA PUSH-PULL SWITCH 5.990 5.99
1 1 EA 1 BATTERY 48.990 48.99
CAN 1 EA CAN 0.560 0.56 G
CAN99 1 EA BOTTLE 1.250 1.25 G
CAN12 1 EA 12pk CANS 6.380 6.38 G
BAR 1 EA BAR 0.750 0.75 G
BAR69 1 EA BAR 0.690 0.69 G
BAR99 1 EA BAR 0.990 0.99 G
789 1 EA WILRICH V BOLT 8.870 8.87
987 1 EA WOMEN'S DEERSKIN GLOVES 23.290 23.29
---------
Groc. Tax . . 0.53 Groc. Total . . 10.62
Sales Tax . . 6.97 Merchandise . . 87.14
TOTAL . . W1 105.26 W0 **
Authorized Signature X)___________________________________________
Thank you for shopping at Discount Ag Center!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
Mar 10th, 2009, 02:06 PM
#11
Thread Starter
Addicted Member
Re: Slow, sporadic print
Ok, I think I'm getting close to eliminating the third party app.
This site ( http://support.microsoft.com/kb/q154078/ ) Gives the API to print RAW data to the printer. This is what I need to do, but I suck at getting API's to work for me. So, any help on what exactly I need to change up to get it to work.
-RT
-
Mar 10th, 2009, 03:51 PM
#12
Re: Slow, sporadic print
unfortunately i can not test any of this as my dot matrix printers are well gone, but you should be able to send the file to the printer as text, the printer will see the control characters and treat them as such
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 10th, 2009, 04:27 PM
#13
Thread Starter
Addicted Member
Re: Slow, sporadic print
I have the app working with the info in the link in my prev. post.
It is now running on the PC's at my location for testing, if all runs well for about 2 weeks then I export to other locations, if not then I'm back to square1.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|