Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted

If the file is written correctly as you have said, then the problem should be in the way you're 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 it's more flexible because you don't have to change your file-writing routine if any of the fields' length changes. Of course, that's just me :) .

Posted

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!

  • *Gurus*
Posted

Hi,

 

I would guess you're seeing this problem because you're showing the text in a font which isn't fixed-pitch, i.e. spaces and letters won't all be the same size. To display data like that you need to use a fixed pitch font such as Courier New.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
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 doesn't 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!
  • *Experts*
Posted
If you use Courier New, you are safe; if I'm not mistaken, *every* computer with Windows comes installed with Courier New, regardless of options chosen during install. I'm fairly sure it's one of the required fonts.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...