Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 by Thearon Willis, Bryan Newsome; ISBN: 9780764574016
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 24th, 2008, 11:30 AM
Registered User
 
Join Date: Feb 2008
Location: Charlottesville, Virginia, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Errata for Page 235

The errata (posted on 01/06/2006) page 235, "Text Deletions", is clear that the "entire section along with the code had to be rewritten...due to changes in the software."

I have downloaded code from your site (hoping that it would be the rewritten version), and it does not appear to have been rewritten.

This error occurs: 'AddressOf' operand must be the name of a method (without parentheses).

Where is the rewritten section? Thanks.

  #2 (permalink)  
Old May 27th, 2008, 05:02 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

You can download the code for Beginning Microsoft Visual Basic 2008 which has the updated code for printing. This code should work in Visual Basic 2005 with no problems.

Thearon
  #3 (permalink)  
Old May 31st, 2008, 03:31 PM
Registered User
 
Join Date: Feb 2008
Location: Charlottesville, Virginia, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. I am new at this and had to tinker around a bit, but did get it to work.

Please update the errata for page 234 to include that the rewritten code can be found in CHAPTER 8 of the code download for Beginning Visual Basic 2008. It's Chapter 7 in the 2005 book.


  #4 (permalink)  
Old June 30th, 2008, 04:49 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

OK, here it is. This example assumes you have text in a textbox that you want to print.

Add a PrintDialog control to your form. Then add the following class level declarations:

    Private strPrintRecord As String
    Private WithEvents DialogsPrintDocument As PrintDocument

Now add this procedure:

    Private Sub DialogsPrintDocument_PrintPage(ByVal sender As Object, _
        ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
        Handles DialogsPrintDocument.PrintPage

        'Declare variables
        Dim intCharactersToPrint As Integer
        Dim intLinesPerPage As Integer
        Dim strPrintData As String
        Dim objStringFormat As New StringFormat
        Dim objPrintFont As New Font("Arial", 10)
        Dim objPageBoundaries As RectangleF
        Dim objPrintArea As SizeF

        'Get the page boundaries
        objPageBoundaries = New RectangleF(e.MarginBounds.Left, _
            e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)

        'Get the print area based on page margins and font used
        objPrintArea = New SizeF(e.MarginBounds.Width, _
            e.MarginBounds.Height - objPrintFont.GetHeight(e.Graphics))

        'Break in between words on a line
        objStringFormat.Trimming = StringTrimming.Word

        'Get the number of characters to print
        e.Graphics.MeasureString(strPrintRecord, objPrintFont, objPrintArea, _
            objStringFormat, intCharactersToPrint, intLinesPerPage)

        'Get the print data from the print record
        strPrintData = strPrintRecord.Substring(0, intCharactersToPrint)

        'Print the page
        e.Graphics.DrawString(strPrintData, objPrintFont, Brushes.Black, _
            objPageBoundaries, objStringFormat)

        'If more lines exist, print another page
        If intCharactersToPrint < strPrintRecord.Length Then
            'Remove printed text from print record
            strPrintRecord = strPrintRecord.Remove(0, intCharactersToPrint)
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub

Finally double click on the Print button on your form and add this code:

    Private Sub btnPrint_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnPrint.Click

        'Instantiate a new instance of the PrintDocument
        DialogsPrintDocument = New PrintDocument

        'Set the PrintDialog properties
        With PrintDialog1
            .AllowCurrentPage = False
            .AllowPrintToFile = False
            .AllowSelection = False
            .AllowSomePages = False
            .Document = DialogsPrintDocument
            .PrinterSettings.DefaultPageSettings.Margins.Top = 25
            .PrinterSettings.DefaultPageSettings.Margins.Botto m = 25
            .PrinterSettings.DefaultPageSettings.Margins.Left = 25
            .PrinterSettings.DefaultPageSettings.Margins.Right = 25
        End With

        If PrintDialog1.ShowDialog = DialogResult.OK Then
            'Set the selected printer settings in the PrintDocument
            DialogsPrintDocument.PrinterSettings = _
                PrintDialog1.PrinterSettings

            'Get the print data
            strPrintRecord = txtFile.Text

            'Invoke the Print method on the PrintDocument
            DialogsPrintDocument.Print()
        End If
    End Sub


Thearon
  #5 (permalink)  
Old June 30th, 2008, 04:51 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

As a side note to all, you can open any *.vb file in your favorite text editor to view the code. You can also open *.vb files from VB 2008 in the VB 2005 IDE to view the code. You just can't open projects from 2008 in 2005.

Thearon
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERRATA on page 388 NadAf BOOK: Ivor Horton's Beginning Visual C++ 2005 0 August 15th, 2007 09:40 PM
Errata page 182 tpangborn BOOK: Ivor Horton's Beginning Visual C++ 2005 0 May 21st, 2006 09:19 PM
Errata, page 37 theoxylo BOOK: Professional Java Development with the Spring Framework 0 December 6th, 2005 06:55 PM
Errata Page 664 Chrisull BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 November 24th, 2005 08:36 AM
Errata Page bonehead BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 June 27th, 2004 08:45 AM



All times are GMT -4. The time now is 06:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.