I am here with given my one problem, is mentioned here below;
I am beginner to visual basic programming after qualified VB6. And I wish to have some more experience for this programming. Hence I need some procedure on codling's for direct printing procedures. This is under a trial basis. Now I need your help on the subject that is coding for direct printing. My problem is in my report structure the amount, rate are not placed correctly right justification. The codes I used 1-rptjustfyright in code procedure area and also I select1-Rightjustify in the txtItemAmt2.Text in text box properties. The out put of the said value are not set to Right justified. The coding I written which is as given below. Please.

' The following is my Direct printing codings under trial :
‘==============

Private Sub cmdPrint_Click()
Dim nP As Single
Dim nGt As Currency
cmdLast2_Click

txtNo2.Alignment = rptJustifyRight
txtItemAmt2.Alignment = rptJustifyRight
nP = Val(txtItemTot2.Text)
nGt = Format(txtGrandTots2.Text, "##,##0.00")

'to place a blank-line..Here spc(7) means a seven chareacter size is blank from paper most margin end.

Printer.Print
Printer.Print
Printer.Print Spc(7); "PAN :"; Tab(60); "Cash-Bill No:"; Spc(2); txtCustId3.Text
Printer.Print Spc(7); "Dt:"; txtDt.Text; Tab(55); "PHONE: 958181-227602"
Printer.Print

Printer.Print Spc(7); "SRI SHANTERI KAMAKSHI NILAYA, BETTAMAKKI, THIRTHAHALLI"

Printer.Print Spc(7); "Mr/Mrs.."; Spc(3); txtCustName2.Text;
Printer.Print
Printer.Print Spc(7); "-----------------------------------------------------------------------------------------------"
Printer.Print Spc(7); "S.No."; Tab(14); "Qtty"; Tab(22); "Particulars"; Tab(59); "Rate"; Tab(69); "Amount"
Printer.Print Spc(7); "-----------------------------------------------------------------------------------------------"
cmdFirst2_Click
'cmdFirst2_Click
If txtNo2.Text = "1" Then
txtNo2.Alignment = 1 - JustifyRight
Printer.Print Spc(7); Val(txtNo2.Text);
Printer.Print Tab(14); Format(txtQtty2.Text, "##,##0.000");
Printer.Print Tab(22); txtItName2.Text;
txtRate2.Alignment = 1 - JustifyRight
Printer.Print Tab(59); Format(txtRate2.Text, "##,#00.00");
txtItemAmt2.Alignment = 1 - JustifyRight
Printer.Print Tab(71); Format(txtItemAmt2.Text, "##,#00.00")
cmdNext2_Click '2nd...
txtNo2.Alignment = 1 - JustifyRight
Printer.Print Spc(7); Val(txtNo2.Text);
Printer.Print Tab(14); Format(txtQtty2.Text, "##,##0.000");
Printer.Print Tab(22); txtItName2.Text;
txtRate2.Alignment = 1 - JustifyRight
Printer.Print Tab(59); Format(txtRate2.Text, "##,#00.00");

txtItemAmt2.Alignment = 1 - JustifyRight
Printer.Print Tab(71); Format(txtItemAmt2.Text, "##,#00.00")

Do Until myset2.EOF Or myset2(1) = nP
cmdNext2_Click
txtNo2.Alignment = 1 - JustifyRight
Printer.Print Spc(7); Val(txtNo2.Text);
Printer.Print Tab(14); Format(txtQtty2.Text, "##,##0.000");
Printer.Print Tab(22); txtItName2.Text;
txtRate2.Alignment = 1 - JustifyRight
Printer.Print Tab(59); Format(txtRate2.Text, "##,#00.00");
txtItemAmt2.Alignment = 1 - JustifyRight
Printer.Print Tab(71); Format(txtItemAmt2.Text, "##,#00.00")
Loop
Else
MsgBox "The selection could not be reach", vbInformation
End If
Printer.Print Spc(7); "-----------------------------------------------------------------------------------------------"
cmdLast2_Click
Printer.Print Spc(7); "Total Items:"; Spc(2); txtItemTot2.Text; Tab(28); txtHamali.Text; "Hamali:"; Tab(42); txtMisc.Text; "Misc:"; Tab(60); "Gr.Tot:"; Spc(3); Format(txtGrandTots2.Text, "##,##0.00")
Printer.Print Spc(7); "-----------------------------------------------------------------------------------------------"
Printer.Print Spc(7); Tab(30); "THANKQ ..Visit again"

Printer. Print Spc(7); "E & O E"
Printer.NewPage ' to close the same page
Printer.EndDoc ' printer works end.
cmdLast2_Click
Disply_Data2
End Sub
‘============== Here closes Direct printing job codings:
Please sir.

With regards
Devadas Nayak H
My email: dhnayak@rocketmail.com

What you may want/need to do is to capture the currentx/y of the printer object, use the textwidth property of the form, and calculate where you want to have the right side of the text to line up minus the textwidth. After that you would set the currentx/y as needed, do your print of your last piece of information and move on to the next line...

Good Luck

What you may want/need to do is to capture the currentx/y of the printer object, use the textwidth property of the form, and calculate where you want to have the right side of the text to line up minus the textwidth. After that you would set the currentx/y as needed, do your print of your last piece of information and move on to the next line...

Good Luck

---------My reply.....

Thank you very much to give your point to solve ideas. I tried several types and after I able to some code procedure to solve in this print text with rt.justification codings . I am using text matter by counting each space to space using few Add procedures to task the printing place exactly. My trial example on your few ideas, is given here under. In another angle our view is, we need to optimize and simple coding methods and is not made till day. But solved. Pl. see the examples.


Printer.Print Spc(3); "Mr/Mrs.."; Spc(3); txtCustName2.Text;
Printer.Print
Printer.Print Spc(3); "-----------------------------------------------------------------------------------------------"
Printer.Print Spc(3); "S.No."; Tab(14); "Qtty"; Tab(22); "Particulars"; Tab(59); "Rate"; Tab(69); "Amount"
Printer.Print Spc(3); "-----------------------------------------------------------------------------------------------"
cmdFirst2_Click
'cmdFirst2_Click
If txtNo2.Text = "1" Then
myLen_sl
myLen_Qty

myLen_Rate
myLen_Amt
cmdNext2_Click '2nd...
myLen_sl
myLen_Qty
myLen_Rate
myLen_Amt

Do Until myset2.EOF Or myset2(1) = nP
cmdNext2_Click '3rd... and to reach end
myLen_sl
myLen_Qty
Printer.Print Tab(17); txtItName2.Text;
myLen_Rate
myLen_Amt
Loop
Else
MsgBox "The selection could not be reach", vbInformation
End If
Printer.Print Spc(3); "-----------------------------------------------------------------------------------------------"
cmdLast2_Click
Printer.Print Spc(3); "Total Items:"; Spc(2); txtItemTot2.Text; Tab(28); txtHamali.Text; "Hamali:"; Tab(42); txtMisc.Text; "Misc:"; Tab(60); "Gr.Tot:"; Spc(1); Format(txtGrandTots2.Text, "##,##0.00")
Printer.Print Spc(3); "-----------------------------------------------------------------------------------------------"
Printer.Print Spc(3); Tab(30); "THANKQ ..Visit again"
Printer.Print
Printer.Print Spc(3); "E & O E"; Tab(55); "U/t Home Job Works"
Printer.NewPage ' to close the same page
Printer.EndDoc ' printer works end.
cmdLast2_Click
Disply_Data2
End Sub

‘The Add procedure are created to three different textboxes. All are similar. But one is given as a example.

'The following code need to seek corect right justifying
' for txtItemAmt2.text in print outputs.
Private Sub myLen_Amt()
Dim myString2 As String
Dim myLen_Amt As Integer
myString2 = txtItemAmt2.Text
myLen_Amt = Len(myString2) ‘Where len counts total numeric character inclues comma,points.

If myLen_Amt = 4 Then
Printer.Print Tab(71); Format(txtItemAmt2.Text, "##,##0.00")
ElseIf myLen_Amt = 5 Then
Printer.Print Tab(70); Format(txtItemAmt2.Text, "##,##0.00")
ElseIf myLen_Amt = 6 Then
Printer.Print Tab(69); Format(txtItemAmt2.Text, "##,##0.00")
ElseIf myLen_Amt = 7 Then
Printer.Print Tab(68); Format(txtItemAmt2.Text, "##,##0.00")
ElseIf myLen_Amt = 8 Then
Printer.Print Tab(67); Format(txtItemAmt2.Text, "##,##0.00")
ElseIf myLen_Amt = 9 Then
Printer.Print Tab(66); Format(txtItemAmt2.Text, "##,##0.00")

End If
End Sub
Thank you very much[dhnayak/QUOTE]

printer.print space(12-len(format(txtvalue.text,"######0.00"))) ; format(txtvalue.text,"######0.00")
By this method you can add prefix spaces and get your content right aligned.

Try using monospaced fonts or fonts that are not proportional such as True Type Fonts (TTF). If your printer switches the font from a font that is used on your form, and it switches to a monospace font, then the spacing will be off. Sometimes your printer will supply fonts to use with the printer specifically

This article has been dead for over six months. Start a new discussion instead.