Question Batch Printing Part 2

takwirira

Member
Joined
Dec 21, 2007
Messages
23
Programming Experience
Beginner
I have the code below, that is throwing errors when I try to print

VB.NET:
Public Class Print
    Dim spl As String
    Dim file As String = IO.Path.Combine("c:\invoices\", "222153    .htm")
    Private Sub runPrintJobs()
        Dim t As New Threading.Thread(AddressOf printthread)
        t.IsBackground = True
        t.SetApartmentState(Threading.ApartmentState.STA)
        t.Start()
    End Sub

    Private Sub printthread()
        Dim wb As New WebBrowser
        wb.Navigate(file)
        Do Until wb.ReadyState = WebBrowserReadyState.Complete
            Application.DoEvents()
        Loop
        wb.Print()
        wb.Dispose()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        looper()
    End Sub
    Private Sub looper()

        Dim strFile As String
        Dim strList As String

        strFile = Dir("C:\Invoices\*.*")

        While Len(strFile) > 0
            strList = strList & strFile
            strFile = Dir()
            ListBox1.Items.Add(strList)
            strList = ""
        End While

        Do

            spl = ListBox1.Items.Item(0).ToString
            file = IO.Path.Combine("C:\Invoices\", spl)
            runPrintJobs()
            'remove item
            ListBox1.Items.RemoveAt(0)

        Loop Until ListBox1.Items.Count = 1


    End Sub

End Class

Can anybody see what could be wrong with my code? if I were to take out the loop i.e. printing more than one file it prints fine????
 

Latest posts

Back
Top