Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 11th, 2003, 02:07 PM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB 6.0 Printing problem

I am using VB 6.0 to write an application. There I use Microsoft Flexgrid for tabulated data. The dollar amounts in the grids on the screen are properly aligned. But when I send these figures to the printer they align from the left and as a result the decimal points don't line up. Would some one be kind enough to help me out with this problem. Thanks.

Gingira


 
Old November 11th, 2003, 05:47 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

could you see us the code you use for printing

Ahmed Ali
Software Developer
 
Old November 11th, 2003, 06:55 PM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by alyeng2000
 could you see us the code you use for printing

Ahmed Ali
Software Developer
Mr. Ali
Thank you for your response. As advised by you I am sending a part of the printing routine:

Private Sub Print_Click()
...........
more coding above here which has no problem.

The part below is collecting data from FlexGrid "Table" and sending to to printer. Cannot align the numbers to line up the decimal points.
.........
Margin = 2000
row = 0
col = 0
Table.col = col
Table.row = row

Do While Table.Text <> ""
Table.col = col
Table.row = row
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin
Printer.Print Table.Text
Table.col = 1
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin + 2580
Printer.Print Table.Text
Table.col = 2
Printer.RightToLeft = True
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin + 2580 + 1750
Printer.Print Table.Text

Table.col = 3
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin + 2080 + 1150 + 2580
Printer.RightToLeft = True
Printer.Print Table.Text
Table.col = 4
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin + 2580 + 1150 + 2080 + 2080
Printer.RightToLeft = True
Printer.Print Table.Text
row = row + 1
col = 0
Table.col = col
Table.row = row
Loop

Printer.EndDoc


End Sub

 
Old November 12th, 2003, 03:13 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

as i understood, that the printing is left aligned so....
try starting col from 4 to 0 instead from 0 to 4

'modified code

Private Sub Print_Click()
...........
more coding above here which has no problem.

The part below is collecting data from FlexGrid "Table" and sending to to printer. Cannot align the numbers to line up the decimal points.
.........
Margin = 2000
row = 0
col = 0
Table.col = col
Table.row = row

Do While Table.Text <> ""
Table.col = col
Table.row = row
Table.col = 4
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin
Printer.Print Table.Text
Table.col = 3
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin + 2580
Printer.Print Table.Text
Table.col = 2
Printer.RightToLeft = True
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin + 2580 + 1750
Printer.Print Table.Text

Table.col = 1
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin + 2080 + 1150 + 2580
Printer.RightToLeft = True
Printer.Print Table.Text
Table.col = 0
Printer.CurrentY = 9200 + row * 200
Printer.CurrentX = margin + 2580 + 1150 + 2080 + 2080
Printer.RightToLeft = True
Printer.Print Table.Text
row = row + 1
col = 0
Table.col = col
Table.row = row
Loop

Printer.EndDoc


End Sub


also try to exit loop when you reach the last row like
If Row = 10 Then Exit Do


Ahmed Ali
Software Developer
 
Old November 12th, 2003, 12:51 PM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

  Thanks for your suggestion but unfortunately it did not work. Selecting columns from right to left
on the FlexGrid table and printing right most column first on the printer did not help. It was still aligning from the left. I need a printer code to justify the output from the printer right to left. Though I used the "Right to Left=TRUE" function in my coding but frankly speaking I don't know what does it do. Whatever it is, it does not do what it is supposed to do. To get an idea about right to left function I tried to modify the "Right to left"property of a text box to a TRUE state but it never goes to TRUE state. It always remains in FALSE state. Nevertheless, please keep in mind. If you come up with a solution please let me know. I can see a good number of people have read my message but you are the only one who responded.

 
Old December 4th, 2003, 01:21 PM
Authorized User
 
Join Date: Oct 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try padding each entry with spaces at the front.

Add a function like this:

      Public function fmat(x as string)as string
          dim l as integer, m as integer
          l=len(x)
          m=10-l 'assuming 10 is the width of your column


 
Old December 4th, 2003, 01:26 PM
Authorized User
 
Join Date: Oct 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got cut off.
Try padding each entry with spaces at the front.

Add a function like this:

      Public function fmat(x as string)as string
          dim l as integer, m as integer
          l=len(x)
          m=10-l 'assuming 10 is the width of your column
          fmat=space(m) & x
      end function

      Instead of
      printer.print.table.text
      put
      x=table.text
      printer.print.fmat(x)

Worth trying!




 
Old December 5th, 2003, 05:24 AM
Authorized User
 
Join Date: Oct 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got cut off again!

Yesterday I was re-inventing the wheel: you can do it without creating a function; with a fixed-length string and rset

At the beginning of the module:
     dim x as string * 10 'or as many characters as necessary
                             'to accommodate your longest piece
                             'of data
Where you have
     Printer.print table.text
put
     rset x = table.text
     printer.print x

That should do it.

The printer commands in VB are pretty primitive. I often use Excel VBA instead, to be able to print out onto a spreadsheet.

From what I can see, it will be even more difficult in VB.Net!



 
Old December 5th, 2003, 11:03 AM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Would it not be easier to create a report. Reports are meand for printing, forms are not.



Sal
 
Old January 19th, 2005, 07:28 AM
Registered User
 
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

************************************************** ********************

I also got the same problem while printing it. I will show you how I
solved the problem.
I suppose even after using RSet to right align the string, you didn't
get it right aligned. The problem is not with the RSet Function. It just works what it was programmed to do. What RSet does is pad with
spaces to the left. But when it gets to the printer since different
characters have different widths it wont be aligned properly.
We can solve this problem by using the printers TextWidth Property

The code is as follows

Private Sub Print_Click()
   Dim num(2) As Double
   'code to initialize the array
   Dim Margin As Integer
   Dim Row As Integer
   Dim i As Integer
   num(0) = 33.3
   num(1) = 2
   num(2) = 45.67
   Margin = 500
   Row = 4500
   Dim tNum As String
   For i = 0 To 2
     tNum = FormatNumber(num(i), 2)
     Printer.CurrentX = Margin + 1000 - Printer.TextWidth(Trim(tNum))
     Printer.CurrentY = Row + i * 200
     Printer.Print Trim(tNum)
   Next
   Printer.EndDoc
End Sub

Try this code and let me know your experience

shahaludeen N
Student
mail Id: [email protected]
************************************************** ********************






Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing in VB 2005 BroadwayLion Visual Basic 2005 Basics 7 February 19th, 2008 11:28 AM
Printing problem dot matrix printer using VB.Net [email protected] Crystal Reports 0 February 21st, 2006 11:29 AM
vb-printing on DMP kumar Beginning VB 6 1 September 30th, 2004 06:24 AM
Printing Images in VB sgluzberg VB How-To 1 July 21st, 2004 10:03 PM
Printing in VB sathisemail VB How-To 0 March 10th, 2004 02:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.