Click here to Skip to main content
16,005,162 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionimages in the button Pin
shri509-Oct-07 14:50
shri509-Oct-07 14:50 
AnswerRe: images in the button Pin
Luc Pattyn9-Oct-07 14:56
sitebuilderLuc Pattyn9-Oct-07 14:56 
QuestionCreating Tab Delimited Output File Pin
Swisher249-Oct-07 13:18
Swisher249-Oct-07 13:18 
AnswerRe: Creating Tab Delimited Output File Pin
Christian Graus9-Oct-07 13:23
protectorChristian Graus9-Oct-07 13:23 
AnswerRe: Creating Tab Delimited Output File [modified] Pin
Luc Pattyn9-Oct-07 13:55
sitebuilderLuc Pattyn9-Oct-07 13:55 
AnswerRe: Creating Tab Delimited Output File Pin
Dave Kreskowiak9-Oct-07 17:14
mveDave Kreskowiak9-Oct-07 17:14 
GeneralRe: Creating Tab Delimited Output File Pin
Swisher2410-Oct-07 6:44
Swisher2410-Oct-07 6:44 
GeneralRe: Creating Tab Delimited Output File Pin
Dave Kreskowiak10-Oct-07 7:12
mveDave Kreskowiak10-Oct-07 7:12 
You have two problems. The first is that different application interpret tabs differently. One may replace a tab character with a bunch of spaces and another might add a bunch of whitespace to hit the next tabstop in it's rendering engine, while another might do something different and add a different amount of whitespace for each tab.

The second is that Arial is a proportional font, meaning that each character is rendered in a cell reletive to the size width of the character. Spaces can be very narrow compared to all the captial letters. Mono-spaced fonts have every character, even spaces, rendered in cells of the exact same width for every character. This means that a space is exactly the same width as, say, a captial W.

If you're writing to a text file (*.TXT), the font doesn't matter since it's not used in the file. What screws up the formatting is the application that is rendering the text. For instance, if you open the file in Notepad and configure Notepad to use the Arial font, the report layout will be severly messed up. Change the font Notepad uses to something like Lucida Console, which is mono-spaced, and column alignment changes.

But now you have a problem with the size of the columns. Assume that you have two lines of text int the file, laid out like this:
sometext[TAB]some more text
someotherlongertext[TAB]even more text

Say Notepad uses a tabstop every one inch. The "sometext" in the first line of the file is shorter than than one inch. The tab will move the cursor to the one mark and then the rest of the line shows up.

Now, for the second line, the first part of it, "someotherlongertext", is longer one inch. Well, the tab will move the cursor to the two inch mark, where the rest of the line will be rendered. And if you haven't figured it out yet, the second column will not be lined up.

There-in lies the problem with using Tabs to do reporting. Each line will have to know how it's going to be rendered and have a variable number of tabs between columns to line them up. Since your application can't possibly know how the text file is going to be rendered, it's impossible to predict the number of tabs needed between columns for each line in the report.


What's the solution?? Use a dedicated reporting tool, like CrystalReports, to generate the report.

If it has to be in a text file, replace the tabs with a known number of spaces. You're going to have to do more work like keeping track of how many characters are in each field and how wide (in characters) each field can hold. Then you can calculate the number of spaces you need to add between those two fields to get them to line up.

Even then, use a proportional font to show the text and the spaces won't even line the columns up.




A guide to posting questions on CodeProject[^]

Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007


GeneralRe: Creating Tab Delimited Output File Pin
Swisher2410-Oct-07 7:34
Swisher2410-Oct-07 7:34 
QuestionMDI form... Pin
manni_n9-Oct-07 12:03
manni_n9-Oct-07 12:03 
AnswerRe: MDI form... [modified] Pin
mr_lasseter9-Oct-07 15:19
mr_lasseter9-Oct-07 15:19 
GeneralRe: MDI form... Pin
manni_n10-Oct-07 2:21
manni_n10-Oct-07 2:21 
GeneralRe: MDI form... Pin
mr_lasseter10-Oct-07 2:51
mr_lasseter10-Oct-07 2:51 
GeneralRe: MDI form... Pin
manni_n10-Oct-07 5:17
manni_n10-Oct-07 5:17 
GeneralRe: MDI form... Pin
mr_lasseter10-Oct-07 5:20
mr_lasseter10-Oct-07 5:20 
GeneralRe: MDI form... Pin
manni_n10-Oct-07 10:39
manni_n10-Oct-07 10:39 
GeneralRe: MDI form... Pin
mr_lasseter10-Oct-07 15:20
mr_lasseter10-Oct-07 15:20 
QuestionHow can I create a tab dynamically? Pin
Big Ralph9-Oct-07 8:55
Big Ralph9-Oct-07 8:55 
AnswerRe: How can I create a tab dynamically? Pin
Patrick Etc.9-Oct-07 10:47
Patrick Etc.9-Oct-07 10:47 
GeneralRe: How can I create a tab dynamically? Pin
Big Ralph9-Oct-07 18:03
Big Ralph9-Oct-07 18:03 
GeneralRe: How can I create a tab dynamically? Pin
Tom Deketelaere9-Oct-07 22:41
professionalTom Deketelaere9-Oct-07 22:41 
QuestionDateformat! Pin
jensenx9-Oct-07 7:25
jensenx9-Oct-07 7:25 
AnswerRe: Dateformat! Pin
Dave Kreskowiak9-Oct-07 7:34
mveDave Kreskowiak9-Oct-07 7:34 
GeneralRe: Dateformat! Pin
jensenx9-Oct-07 15:16
jensenx9-Oct-07 15:16 
AnswerRe: Dateformat! Pin
GuyThiebaut9-Oct-07 8:23
professionalGuyThiebaut9-Oct-07 8:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.