CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Location
    ohio
    Posts
    300

    word wrap to a text file

    I need code to wrap data from a database field into a text file. I can do short fields just fine but the long ones need wrapped.

    the code i have will appear to wrap ok when viewing with Wordpad, Notepad or on Email attachments but when printed it is broken up into funny sections.

    I heard that the API can do this.

    ANY info on where i can get info on printing would be a big help also. printing seems to be tricky with VB6.

    can someone help me?

    Ron



  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: word wrap to a text file

    Look at the following code. If you are wrapping the text to a file, then the following method is OK. It wraps on the basis of character count.

    If you are wrapping to a graphical device such as a picturebox, then you need to use the GetTextExtentPoint32() API. The method is similar except that you use the condition GetTexctExtentPoint32(...)<picturebox.scalewidth in the do while loop. In addition, you may want to use the SetTextJustification() API to justify it.


    private Sub Command1_Click()
    dim str1 as string, str2 as string, str3 as string
    dim curpos as integer

    str1 = "I need code to wrap data from a database field into a text file. I can do short fields just fine but the long ones need wrapped. the code i have will appear to wrap ok when viewing with Wordpad, Notepad or on Email attachments but when printed it is broken up into funny sections. I heard that the API can do this. ANY info on where i can get info on printing would be a big help also. printing seems to be tricky with VB6. can someone help me?"
    MsgBox str1
    Do While len(str1) > 80
    curpos = 1
    str2 = mid$(str1, curpos, 80)
    curpos = InStrRev(str2, " ")
    str2 = Left$(str2, curpos)
    str1 = mid$(str1, curpos)
    str3 = str3 & LTrim(str2) & vbCrLf
    Loop
    MsgBox str3
    End Sub




    For printing, if it is plain text, then you can use
    Printer.Print text1.text

    If it's the contents of the picturebox that you want to print, then use
    Printer.PaintPicture picture1.image, 0, 0

    You may also want to let the user choose the printer to print to using the Printer Common Dialog Box.




  3. #3
    Join Date
    Apr 2001
    Location
    ohio
    Posts
    300

    Re: word wrap to a text file

    i was not able to get your code to work.

    i did find code to do this for me. it takes the lines one by one from a text box and i can put them into another text box, disk file, or to the printer.


    thanks anyway

    Ron



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

Featured