Whitespace preservation

martialarts

Well-known member
Joined
Jun 20, 2003
Messages
59
Location
Chicago Area
Hi. I am using VB.NET 2002 Standard. My program creates a textfile of multiples formatted lines. The lines appear similar to the following:

Magnesium 50 60 38 48 65 HIGH
Calcium 60 70 62 68 40 LOW
Albumin 10 20 12 18 25 HIGH

The program calculates the whitespace to output to the textfile to make the lines seem like a series of justified columns, similar to a table. The file is being written correctly, but when I open the datafile at a later time in the program, it destroys my perfect whitespacing and the columns are jagged and inconsistent. I am rying to place the text into a label, similar to a print preview. Streamreader and fileopen created the same results. Is there a way I can make this work or do I have to change the format of the text file to a delimited format such as:

Magnesium,50,60,38,48,65,HIGH

and then add the whitespace when I read from the file and output it to the label? Will this delimited format even allow me to add the proper whitespace and have it displayed correctly in the program? Thanks!
 
If the file is written correctly as you have said, then the problem should be in the way youre reading the file. Can you post your snippet that reads the file?

Btw, I prefer the csv format because it reduces the file size and its more flexible because you dont have to change your file-writing routine if any of the fields length changes. Of course, thats just me :) .
 
Thanks for responding. Here is the code I am using:

Dim lineOfText As String
Dim dataFile As StreamReader
dataFile = New StreamReader("vpage1.tmp")
lineOfText = dataFile.ReadToEnd
lblText.Text = lineOfText

I have also tried:

FileOpen(1, "vpage1.tmp", OpenMode.Input)
lblText.Text = LineInput(1) & vbCrLf & LineInput(1) _
& vbCrLf & LineInput(1)
FileClose(1)

and several other variants including reading each line individually with streamreader.readline and I have even tried outputting it to a msgbox to see if it had something to do with the text box. Thanks for your time!
 
Hi,

I would guess youre seeing this problem because youre showing the text in a font which isnt fixed-pitch, i.e. spaces and letters wont all be the same size. To display data like that you need to use a fixed pitch font such as Courier New.
 
Thanks. You were right! That also explains why I have had problems aligning columns in other software. I found a short list of fixed-point fonts. I have courier new and lucida console. I am getting ready to deploy this program and I am wondering what will happen if someone doesnt have the fixed-point font on his computer. Will the installer install it or is there something else I can do to make sure it gets installed? I am using VB.NET 2002 standard. Thanks for your time!
 
If you use Courier New, you are safe; if Im not mistaken, *every* computer with Windows comes installed with Courier New, regardless of options chosen during install. Im fairly sure its one of the required fonts.
 

Similar threads

Back
Top