Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 Grid Like Printing In Visual Basic ?

Author  Topic 

amitkumarmadhukar
Starting Member

45 Posts

Posted - 2004-08-05 : 12:57:42
hello professional,
how days r going on

here is another problem for u guys

i am printing a Table ..... in such a manner
Printer.Print Space(10); "Items of Import:-"
Printer.FontBold = False

Printer.Print Space(10); "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Printer.Print Space(15); "Sr"; Space(5); "Description"; Space(5); "Generic"; Space(5); "Unit Price"; Space(5); "Quantity"; Space(5); "Unit of Quantity"; Space(5); "Accessories,if any"; Space(5); " Manufacter's Name"; Space(5); "Brand"; Space(5); "Model Specifications"
Printer.Print Space(10); "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"; Space(10)


Cs.CommandText = "select Item_No,Item_Description,Generic_Description,Unit_Price,Quantity,Unit_Of_Quantity,Accessaries,Manufacter_Name,Brand,Model_Specification from Fourthbe Where Be_Id='" + BeNo + "'"
Cs.Execute

With Cs.Execute
Do While Not .EOF

Printer.Print Space(15); "" + .Fields(0) + ""; Space(5); "" + .Fields(1) + ""; Space(8); "" + .Fields(2) + ""; Space(8); "" + .Fields(3) + ""; Space(8); "" + .Fields(4) + ""; Space(8); "" + .Fields(5) + ""; Space(8); "" + .Fields(6) + ""; Space(8); "" + .Fields(7) + ""; Space(8); "" + .Fields(8) + ""; Space(8); "" + .Fields(9) + ""
Printer.Print
.MoveNext
Loop
End With

it does not print grid like structure, here the length of each fields may vary, they have sometimes full length value or some times no values

how alligned this grid


some of you suggest me left(value1+space(100),100) but sorry to say those this technique doesn't work
or i am wrong

please correct my Format String




amit kumar madhukar

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-08-05 : 13:17:39
why don't you show us how you tried to implement that suggestion? Because it DOES work, but it may not if you didn't implement it correctly or understand the what that particular technique is trying to accomplish.

- Jeff
Go to Top of Page

amitkumarmadhukar
Starting Member

45 Posts

Posted - 2004-08-06 : 05:26:30
if i don't know or don't implement the coding in better way then please give me the appropriate way i am very thankful to you

amit kumar madhukar
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-08-06 : 08:48:11
let's say you want to print 3 columns:

Name, Date, Age

Name will be 40 characters long, justified left.
Date will be in the mm/dd/yyyy format, so that's 10 characters, justified right.
Age will be only 3 characters long, also justified right.

Between each column you will have 2 spaces.

First, then, print your headings. Print each word to describe the heading, then as many spaces as you need to be sure things line up:


print "Name" & space(40 - 4 + 2) & space(10-4) & "Date" & space(2) & "Age"


NOtice i did some math (use the results, not the formula, in your code). For the first column (Name) we want the column to be 40 characters long (40), so we need to add (40-4) spaces after the word "Name" since that word is 4 characters long. Then we need 2 spaces (+2) afterwards.

For the Date column, we want it right justified, so we put the spaces BEFORE the word, and then the 2 spaces after. for the "Age" column, no special tricks are needed.

Does this make sense? Stop reading here if you are not following, and go over it until it becomes clear.

Now we do the same for your data. We need to pad each field with spaces before or after it so that it is wide enough for the column, then add 2 spaces afterwards.

To pad spaces to the variable X so that it is exactly 40 characters long, how can we do that? Well, we need to add (40-(Length of X)) spaces to it -- either before it or after, depending on whether it is right aligned or left aligned. Makes sense?

(note: you can also say: Left(x & space(40),40) or Right(space(40) & x,40) to do the same thing -- does this make sense? try it out, do some testing, see why it works.)

so, here we go, for each line:


print Name & space(40 - Len(Name) + 2) & space(10-len(Date)) & DAte & space(2) & space(3-len(age)) & Age


Does this help?

- Jeff
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2004-08-06 : 10:55:06
Good post, Jeff. I think another problem that might be complicating the issue here is the font he's using. Amit, if you want all values aligned exactly, then you need to use a mono-spaced font for the report data, such as Courier or Lucida. Other fonts have varying widths for each character and that makes it nearly impossible to align the values consistently.

OS
Go to Top of Page

amitkumarmadhukar
Starting Member

45 Posts

Posted - 2004-08-06 : 17:02:55
Sorry Jsmith it does not solving my problem
look again what u give me suggestion if far away from my question

look i a three columns
named, Sr Number,Item Description,Amount

Description of Each Columns are
Sr=Varchar(2),Item Description Varchar(30), and Amount double type varibale


now i use to print in certain loops

assume i execute three time loop
in first loop the actual length of my recordset with each columns as:

[sr]-(1),[Item Description]-21,[Amount]-8

in second loop , it becomes now
[sr]-(1),[Item Description]-15,[Amount]-8

in third and final round it becomes
[sr]-(1),[Item Description]-26,[Amount]-8

thus my output looks like

1--Item Description------452636.52
1--Item Description---452636.52
1--Item Description----------452636.52

but i want printing looks like wheather the length or varibale may change in each iteration example :Invoice Printing where startline of each coloumns are exact linear

1--Item Description------452636.52
1--Item Description------452636.52
1--Item Description------452636.52

can u help me now with better way



amit kumar madhukar
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-06 : 17:28:40
Dup:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=38297

Tara
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-08-06 : 17:39:23
Please re-read my post! you are not even trying to understand the advice given. What part of my post have you tried specifically? And please stop posting this same question as new topics.

Show us exactly how you tried to make use of the advice i gave you.

- Jeff
Go to Top of Page

amitkumarmadhukar
Starting Member

45 Posts

Posted - 2004-08-07 : 02:46:16
sir,
i use ur suggestion in this way


Printer.PaperSize = vbPRPSA4
Printer.Orientation = vbPRORPortrait
Printer.PaperSize = vbPRPSA4
Printer.Font = "Courier" 'Lucida/Courier
Printer.FontSize = 10


Cs.CommandText = "select Item_Description,Generic_Description,Item _Code from BL"

Cs.Execute

With Cs.Execute
Do Until .EOF
Printer.Print .Fields(2) & Space(30 - Len(.Fields(2)) + 5) & Space(30 - Len(.Fields(3))) & .Fields(3)
.MoveNext
Loop
Printer.EndDoc
End With

where
Item_Description's length =30,
Item_Description's length =30, and
Item_Code's length =10


where total length of

amit kumar madhukar
Go to Top of Page

amitkumarmadhukar
Starting Member

45 Posts

Posted - 2004-08-07 : 09:49:34
JSmith Sir ,
Thanks for good suggestions
however ur does not works,
but yet i get my way to solve the problem and i think that ur suggestion without the suggestion of mohodiwas from UAE is worthless,
however mohodiwas not courier but Courier New is the right font

thanks u both

Jsmith ur suggestion does not work fully but it is very near to the solutions

thanks again




amit kumar madhukar
Go to Top of Page
   

- Advertisement -