Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Greetings,

 

I have an application that reads data from a dataset and writes to a text file a formatted version of the data. I have two numeric (double) type fields that I need to write to the file while preserving any spaces to the left of the number (this is requiered by the program that uses the file as input).

 

For example the text is written as "-1000.45" instead of " -1000.45"

 

It needs to be 12 spaces and right justfied. I am reading the data like this.....

 

Public Function WriteTemp(ByVal uid As String)

 

 

code removed for clarity

 

 

 

For i = 0 To _DS.Tables(0).Rows.Count - 1

For innerloop = 0 To 8

line = line + CStr((_DS.Tables(0).Rows(i).Item(innerloop)))

 

Next

innerloop = 0

line = line + " "

For innerloop = 9 To 28

line = line + CStr((_DS.Tables(0).Rows(i).Item(innerloop)))

Next

ezwriter.WriteLine(line)

 

line = ""

Next

ezwriter.Close()

 

 

End Function

Posted

Perhaps this could get you started:

 

Dim writer As New System.IO.StreamWriter(New FileStream ("c:\numspace.txt", FileMode.Append))
    Dim num As System.Double = -12342.35
    writer.WriteLine(System.Convert.ToString(num).PadLeft(12))
    writer.Close()
End Sub

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...