1 Attachment(s)
[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
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
Re: carriage return problems
Post the code that you are using to print with. That may help us to better see your problem.
Re: carriage return problems
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
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:
Printer.FontSize = 12
Printer.Print Text1.Text
Printer.Print Label12.Caption
Printer.Print Text3.Text, Text4.Text, Text5.Text, Text6.Text, Text7.Text, Text8.Text
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.
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.
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
Re: carriage return problems
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!
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:
Private Sub Command1_Click()
Dim i As Integer
Printer.FontSize = 12
Printer.FontName = "Courier New" 'Fixed length font
For i = 0 To UBound(Split(Text3.Text, vbNewLine))
Printer.Print FillSpaces(Split(Text3.Text, vbNewLine)(i), 20);
Printer.Print FillSpaces(Split(Text4.Text, vbNewLine)(i), 15);
Printer.Print FillSpaces(Split(Text5.Text, vbNewLine)(i), 10);
Printer.Print FillSpaces(Split(Text6.Text, vbNewLine)(i), 8);
Printer.Print FillSpaces(Split(Text7.Text, vbNewLine)(i), 8);
Printer.Print FillSpaces(Split(Text8.Text, vbNewLine)(i), 8)
Next
Printer.EndDoc
End Sub
Private Function FillSpaces(ByVal pStr As String, pCount As Integer) As String
Do While Len(pStr) < pCount
pStr = pStr & " "
Loop
FillSpaces = pStr
End Function
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:
Private Function FillSpaces(ByVal pStr As String, pCount As Integer) As String
FillSpaces = pStr & Space(pCount - Len(pStr))
End Function
Is what i'd do, but anyway!
Hope it all helps
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!