Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.Net Align Text columns for printing

Posted on 2014-12-29
3
Medium Priority
?
752 Views
Last Modified: 2014-12-29
Hi Experts, I have to print multiple strings in columns so that it appears like this

Date: 25/12/2014      Time: 08H30        Name: Fred Smith              Age:27    ID Number: 123456
Date: 25/12/2014      Time: 08H30        Name: Harry Robinson      Age:7      ID Number: 456789

which I have programed as

"Date:" & "  "  & STRDAte & "        " & "Time:"  & "  " & STRTime & "       "  &   "Name:" & "  "  & STRName      etc etc  

(Actual values much more diverse but you get the idea)

Due to the differences in the length of the strings, the columns do not line up
I tried VBTab but this had no effect

Any assistance in an example of lining up the columns would be appreciated

Many Thanks
0
Comment
Question by:PNRT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Assisted Solution

by:Ali HND
Ali HND earned 500 total points
ID: 40521571
you can spot fix length for each string.
for example: Date String length = 16 , Time length = 12 , ...
and with string function add spaces to strings that have a less length from defined length
in operation: if Name string length is 50 and you have 'Name: Fred Smith':
calculate length of string with Len() function.
Len<50, you must add 44 spaces
For i=Len(NameStr) to 50
      NameStr= NameStr & " "
Next
So you have Constant String length and print your data like a table.
0
 
LVL 16

Assisted Solution

by:DansDadUK
DansDadUK earned 500 total points
ID: 40521589
With variable length data, you need to make each part a fixed length, so do something like the following pseudo-code (I don't know VB, so can't give you exact code):

(STRName + Fill (maxNameLength with spaces)).Substring(0, maxNameLength)

Open in new window


Also make sure that you are printing with a mono-spaced font (Courier, or Letter Gothic, or similar); most fonts (e.g. Arial, Times New, etc.) are proportionally spaced, where different characters (e.g. i, m) have different widths.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1000 total points
ID: 40522145
There are a PadLeft and PadRight on the String class that enables you to automatically add spaces so that a column will always display with the same number of characters:

...  &   "Name:" & "  "  & STRName .PadRight(25) & "Age:" & "  "  & STRAge .PadRight(10)

In order for this to work properly however (and this is true for most of the other methods), you need to use a non-proportional font so that each character has the same width. Consolas is one I like, because it is very similar to Arial. This is the font used by default in Visual Studio so that code aligns properly.
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question