Results 1 to 13 of 13

Thread: [RESOLVED] carriage return problems

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Belfast
    Posts
    116

    Resolved [RESOLVED] carriage return problems

    Hi have written a small application that has a few text boxes for outputs, the output looks like this: 1.jpg

    when i print it out the printer recognizes the carriage return in the text boxes and will print out a long line over 2 pages, instead of across the page like it should.

    If i enter text manually without a carriage return it will print out across the page, i have tried to use vbNewLine instead of vbCrLf but its still the same, has anyone any ideas as to how i can make the printer recognisze a new line only after the carriage return on last text box?

    If i tried:

    text3.text = text3.text
    text4.text = text4.text etc....
    Would this remove the carriage returns? (havent tried it yet as im about 5 hours away from my printer!!)

    Thanks
    Attached Images Attached Images  

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Belfast
    Posts
    116

    Re: carriage return problems

    looks like what im doing isnt possible or probably just plain stupid!!
    can anyone suggest a better way to have this setup so that printing will be easier and
    alligned prooperly.

    Thanks

  3. #3
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: carriage return problems

    Post the code that you are using to print with. That may help us to better see your problem.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: carriage return problems

    vbCr ?

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Re: carriage return problems

    Does it print the contents of Product down the page, followed by Code then unit Price etc ?

    If that's the case, I have a fair idea of what your problem is

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Belfast
    Posts
    116

    Re: carriage return problems

    Yes da_silvy, it prints the Product down the page, then Code gets printed beside the last entry of product, then list of codes gets printed.....

    this is the code i am using:

    VB Code:
    1. Printer.FontSize = 12
    2. Printer.Print Text1.Text
    3. Printer.Print Label12.Caption
    4. Printer.Print Text3.Text, Text4.Text, Text5.Text, Text6.Text, Text7.Text, Text8.Text
    5. Printer.EndDoc

    Jcs i think vbCr is the same as carriage return and will still tell the printer to return to a new line, thanks for your input though.

  7. #7
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: carriage return problems

    The common way for something like that would be using a listview or a flexgrid, so you can move cell by cell, and print cell by cell at any position you want.
    If, for some reason you want to make it this way (using textboxes) and you know all of them will have the same amount of lines (separated by vbNewLine), maybe you could Split 1 of that textboxes into pieces, and use that index to move 1 by 1 printing each position each time, it will be a little hard, as I said it's not the best way to do it.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Belfast
    Posts
    116

    Re: carriage return problems

    I dont have to use text boxes, its just that my limited experience dosent extend that far!!! I'll do a search on how to use a flexgrid, thanks

  9. #9
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: carriage return problems

    Here is a good thread about flexgrid, the way to make it editable included..
    http://www.vbforums.com/showthread.php?t=360210
    Another
    http://www.vbforums.com/showthread.php?t=360208

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Belfast
    Posts
    116

    Re: carriage return problems

    cheers, jcis, bit over my head here i think, im about 98% complete on this project so i think ill soldier on with text boxes as time is not on my side!!!! I can do it ok with 1 text box but the spacing isnt the best, thanks for the help!

  11. #11
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: carriage return problems

    Quote Originally Posted by paulhenderson
    cheers, jcis, bit over my head here i think, im about 98% complete on this project so i think ill soldier on with text boxes as time is not on my side!!!! I can do it ok with 1 text box but the spacing isnt the best, thanks for the help!
    Ok, but, if you don't have your answer dont mark the thread resolved, there could be a way to do it with textboxes also, I'll give an example here, maybe someone come up with something even better, try..
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim i As Integer
    3.    
    4.     Printer.FontSize = 12
    5.     Printer.FontName = "Courier New"  'Fixed length font
    6.     For i = 0 To UBound(Split(Text3.Text, vbNewLine))
    7.         Printer.Print FillSpaces(Split(Text3.Text, vbNewLine)(i), 20);
    8.         Printer.Print FillSpaces(Split(Text4.Text, vbNewLine)(i), 15);
    9.         Printer.Print FillSpaces(Split(Text5.Text, vbNewLine)(i), 10);
    10.         Printer.Print FillSpaces(Split(Text6.Text, vbNewLine)(i), 8);
    11.         Printer.Print FillSpaces(Split(Text7.Text, vbNewLine)(i), 8);
    12.         Printer.Print FillSpaces(Split(Text8.Text, vbNewLine)(i), 8)
    13.     Next
    14.     Printer.EndDoc
    15. End Sub
    16.  
    17. Private Function FillSpaces(ByVal pStr As String, pCount As Integer) As String
    18.     Do While Len(pStr) < pCount
    19.         pStr = pStr & " "
    20.     Loop
    21.     FillSpaces = pStr
    22. End Function
    Last edited by jcis; Mar 22nd, 2006 at 12:24 PM.

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Re: [RESOLVED] carriage return problems

    For future reference, it's better to name your textboxes and controls something more useful, so you don't need to go back looking at your form to work out what everything is!

    I'd also be inclined to split the strings outside of the loop, otherwise they're being split every iteration.

    e.g.

    dim strProduct() as string, strCode() as string

    strProduct = Split(text3.text, vbnewline)
    etc..

    For i = 0 to Ubound(strProduct)
    printer.print fillspaces(strproduct(i), 20)
    etc
    next

    as for the fillspaces function
    VB Code:
    1. Private Function FillSpaces(ByVal pStr As String, pCount As Integer) As String
    2.     FillSpaces = pStr & Space(pCount - Len(pStr))
    3. End Function

    Is what i'd do, but anyway!

    Hope it all helps

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Belfast
    Posts
    116

    Re: [RESOLVED] carriage return problems

    Hi guys, really good answers there, really apreciate it, sorry it took so long to reply but was enjoying St Patricks day for while!!!!

    Big Thanks!

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