Results 1 to 13 of 13

Thread: [RESOLVED] Slow, sporadic print

  1. #1

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

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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.)?

  3. #3

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

    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?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  6. #6

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

    Re: Slow, sporadic print

    Quote 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.

    Quote 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

  7. #7
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    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.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  9. #9

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

    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.

  10. #10

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

    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 SignatureX)___________________________________________





    Thank you for shopping at Discount Ag Center!!



    

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  11. #11

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

    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

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  13. #13

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

    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
  •  



Click Here to Expand Forum to Full Width