• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

Printing Grid

How can i print 2 or more columns in grid?
My code below will only print 1 column
Please help!
Thanks
Private Sub Command11_Click()
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print GRID.TextMatrix(GRID.Row, 0); GRID.TextMatrix(GRID.Row, 1); GRID.TextMatrix(GRID.Row, 2)
Printer.EndDoc
End Sub

Open in new window

0
Whing Dela Cruz
Asked:
Whing Dela Cruz
  • 17
  • 12
  • 11
4 Solutions
 
JackOfPHCommented:
Try this...

Printer.Print GRID.TextMatrix(GRID.Row, 0)
Printer.Print GRID.TextMatrix(GRID.Row, 1)
Printer.Print GRID.TextMatrix(GRID.Row, 2)
0
 
game-masterCommented:

TRY SUMTHING LIKE THIS...

Private Sub PrintGrid(ctlGrid As Control)
Dim I As Integer
Dim J As Integer
Dim PTab As Integer

   With ctlGrid
       PTab = 20 'Set the first tab value
       
       For J = 0 To .Columns.Count - 1
           .Col = J 'Set the current column
       
           'Send the field to the print line and add the tab.
           'Notice the semicolon at the end of the line.
           Printer.Print Trim$(.Columns(J).Caption); Tab(PTab);
       
           PTab = PTab + 50 'Increment the tab value
       Next
       Printer.Print
       
       For I = 0 To .ApproxCount - 1
           PTab = 20 'Set the first tab value
           
           'This checks to see if a page break is needed
           If Printer.CurrentY + Printer.TextHeight(.Text) > Printer.ScaleHeight - 600 Then
               Printer.NewPage
           End If
           
           For J = 0 To .Columns.Count - 1
               .Col = J 'Set the current column
           
               'Send the field to the print line and add the tab.
               'Notice the semicolon at the end of the line.
               Printer.Print Trim$(.Text); Tab(PTab);
           
               PTab = PTab + 50 'Increment the tab value
           Next
           
           'After each column has printed to the print line
           'a Printer.Print statement without a semicolon will
           'will send the line to the printer and start a new
           'one.
           Printer.Print
           
           On Error Resume Next
           .Row = .Row + 1 'Set the active row
           On Error GoTo 0
           
       Next I
   End With
   Printer.EndDoc
End Sub

Private Sub Command2_Click()
   Call PrintGrid(DataGrid1)
End Sub
0
 
Whing Dela CruzAuthor Commented:
Hi! I tried it but a message say's "Variable not define"  DataGrid1
Can you add some..
Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
game-masterCommented:

changed DataGrid1 with the name of your Grid...


0
 
Whing Dela CruzAuthor Commented:
Hi! another error message say's "Object doesn't  support this property or method
For J = 0 to .columns.count - 1
0
 
game-masterCommented:


check this link as well to find more example...

http://www.experts-exchange.com/simpleSearch.jsp


i hope i can give u idea...


game-master
0
 
JackOfPHCommented:
Did you try my comment?
0
 
Whing Dela CruzAuthor Commented:
yes sir, its working.. but its only print in one column.  How to print more than 2 columns?
Can you add some idea Please..

0
 
JackOfPHCommented:
Do you mean somthing like this output?

ColumnVAlue1         ColumnVAlue2                   ColumnVAlue3
ColumnVAlue1         ColumnVAlue2                   ColumnVAlue3
ColumnVAlue1         ColumnVAlue2                   ColumnVAlue3


Then Try this one:

Printer.Print GRID.TextMatrix(GRID.Row, 0) & vbTab & GRID.TextMatrix(GRID.Row, 1) & vbTab & Printer.Print GRID.TextMatrix(GRID.Row, 2)

0
 
Whing Dela CruzAuthor Commented:
okey thanks! i will try it now...

0
 
JackOfPHCommented:
ooppss... it should be like this


Printer.Print GRID.TextMatrix(GRID.Row, 0) & vbTab & GRID.TextMatrix(GRID.Row, 1) & vbTab & GRID.TextMatrix(GRID.Row, 2)
0
 
Whing Dela CruzAuthor Commented:
Hi! When I try Only the last line has printed. There are 3 columns or line in my grid but it only print one line.
What shall i do now?

grid.bmp
0
 
game-masterCommented:

For i = 0 To GRID.Rows - 1
                Printer.Print GRID.TextMatrix(i, 0) & vbTab & GRID.TextMatrix(i, 1) & vbTab & GRID.TextMatrix(i, 2)
 Next


that should work now..
0
 
JackOfPHCommented:
It should be like this:

Dim i as integer

For i = 0 To GRID.Rows.count - 1
                Printer.Print GRID.TextMatrix(i, 0) & vbTab & GRID.TextMatrix(i, 1) & vbTab & GRID.TextMatrix(i, 2)
 Next


This will print all the rows in your grid...
0
 
game-masterCommented:


i think that is what i have posted Jack..
0
 
Whing Dela CruzAuthor Commented:
Hi!  I tried it but an error appear like "Invalid qualifier"

"Rows is being highlighted"

For i = 0 To GRID.Rows.count - 1

0
 
game-masterCommented:



TRY MY CODE...
REMOVE THE .COUNT...



game-master
0
 
Whing Dela CruzAuthor Commented:
Hi! Thank you so much, I remove the .count now its working...
Can i ask some more questions? or do i need to post this to another question?

its about the alignment

The grid.textMatrix(i, 2) does not align its other example of the result

1 pck    Paracetamol 500mg cap      1,900.00
2 bx      Chloramphenicol  500 cap           865.00
5 pcs   Reload Plus                              300.00
6 pcd   deras ssm                                        362.00

The problem is the alignment of the row
thanks!

 
0
 
game-masterCommented:

it is ok...

the alignment is unorganized because of the different length of the text...
u can align the result have some sort "cheating"....:-)


do sumthng like this...but im not quiet sure it works fine...

Printer.Print GRID.TextMatrix(i, 0) & Space(5) & vbTab & trim(GRID.TextMatrix(i, 1) ) & Space(5)  & vbTab & trim(GRID.TextMatrix(i, 2))

it means that ur adding 5 spaces on each text before the tab..

have some try...

game-master
0
 
JackOfPHCommented:
>>Printer.Print GRID.TextMatrix(i, 0) & Space(5) & vbTab & trim(GRID.TextMatrix(i, 1) ) & Space(5)  & vbTab & trim(GRID.TextMatrix(i, 2))

This will produce the same result, even you put 5 spaces before the tabs...
0
 
JackOfPHCommented:
Any progress here?
0
 
Whing Dela CruzAuthor Commented:
Yes sir, the alignment of  GRID.TextMatrix(i, 0) and GRID.TextMatrix(i, 1) are exactly aligned
but i don't know the GRID.TextMatrix(i, 2) did not align
here's the result

1 pc   Dn Sample            15.00
2 pc   kmj sample2lko         98.00
3 pc   nm Sapmle            89.00

Can you add some?

Thanks!                    
0
 
game-masterCommented:


we have to set specific length of string on the matrix's second column...
let say the maximum length is 30 characters...

we have to do sumthing like this...

Dim i as integer
dim x as integer

For i = 0 To GRID.Rows - 1
         x  = 30 - len(trim(GRID.TextMatrix(i, 1) ))
         Printer.Print GRID.TextMatrix(i, 0) & Space(5) & vbTab & trim(GRID.TextMatrix(i, 1) ) & Space(x)  & vbTab & trim(GRID.TextMatrix(i, 2))

Next

this codes assumes that the allowable length of the matrix column 2 is 30.


game-master
0
 
Whing Dela CruzAuthor Commented:
i"ll try it now thanks

0
 
Whing Dela CruzAuthor Commented:
hi! sorry an error messages say like " invalid procedure call or argument"
0
 
JackOfPHCommented:
Can you show your code?
0
 
game-masterCommented:


on what part of the code shows the error?
0
 
Whing Dela CruzAuthor Commented:
Private Sub Command11_Click()
Dim i As Integer
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Dim x As Integer

For i = 0 To grid.Rows - 1
         x = 30 - Len(Trim(grid.TextMatrix(i, 1)))
         Printer.Print grid.TextMatrix(i, 0) & Space(5) & vbTab & Trim(grid.TextMatrix(i, 1)) & Space(x) & vbTab & Trim(grid.TextMatrix(i, 2))
Next
Printer.EndDoc

End Sub
0
 
game-masterCommented:


good morning!

im sorry for the late reply bcoz i got sicked...

on what line on the codes shows the error?

game-master
0
 
Whing Dela CruzAuthor Commented:
Hi! Thanks, I hope that you are  in good condition right now..
I actually proceed to another project cause my problem on printing doesn't yet been solve.
I'm happy for your coming because i believed that you can help me about this problem.
i will recall it right now and chat you ASAP.
Thank you so much!
0
 
JackOfPHCommented:
May sakit daw? Ows...
0
 
Whing Dela CruzAuthor Commented:
Hi! I'm using this code
For i = 0 To grid.Rows - 1
         x = 30 - Len(Trim(grid.TextMatrix(i, 1)))
         Printer.Print grid.TextMatrix(i, 0) & Space(5) & vbTab & Trim(grid.TextMatrix(i, 1)) & Space(x) & vbTab & Trim(grid.TextMatrix(i, 2))
Next

As i observed upon printing when grid.TextMatrix(i, 1) is composed of long character the alignment will become disorder. But if the character is almost the same length then the printing alignment will have a good alignment.

I tried it many times but still not working.. I hope you can give more ideas
Thanks!

0
 
Whing Dela CruzAuthor Commented:
Hello jackofPh!
saan ka sa pilinas? Poyde mo akong matulungan sa problemang ito!  
0
 
JackOfPHCommented:
Dito sa munoz, nakatira ako sa cubao, ikaw?
0
 
Whing Dela CruzAuthor Commented:
Cebuano po ako! Sa mindanao
Gusto po akong mag pa tutor ng vb.net na maybayad. maari ba kitang ma kuha na magtutor sa skin kahit sa email lang. Mag online po ako sa iyo ng pera, bigay mo lang sa akin ang accnt no. mo. Poyde ma send mo sa akin ang cel no. mo.
Thanks!
0
 
JackOfPHCommented:
Let me think first...
0
 
Whing Dela CruzAuthor Commented:
Okey,  Thanks!
0
 
game-masterCommented:

any progress?
0
 
Whing Dela CruzAuthor Commented:
yes sir, same problem!
Can you help me now?
0
 
game-masterCommented:


unfortunately, that is somehow the limitation of printer.print...
specially with regards to alignment...

as what i have said before, in order to make the alignment correct,
you should set for the specific length of string on each each column..

otherwise, alignment may not look the way as u want....

game-master
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 17
  • 12
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now