writing to text file [modified] ... resolved
-
when I execute the follow code
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click Try With SaveFileDialog1 ' See the code demonstrating the OpenFileDialog control ' for examples using most properties, which are the same ' for both controls, for the most part. ' Add the default extension, if the user neglects to add an extension. ' The default is True. .AddExtension = True ' Check to verify that the output path actually exists. Prompt before ' creating a new file? Prompt before overwriting? ' The default is True. .CheckPathExists = True ' The default is False. .CreatePrompt = False ' The default is True. .OverwritePrompt = True ' The default is True. .ValidateNames = True ' The default is False. .ShowHelp = True ' If the user doesn't supply an extension, and if the AddExtension property is ' True, use this extension. The default is "". .DefaultExt = "txt" ' Prompt with the current file name if you've specified it. ' The default is "". '.FileName = filename3 '//filename3 = .FileName ' lblfilename.Text = SaveFileDialog1.FileName ' The default is "". .Filter = _ "Text files (*.txt)|*.txt|" & _ "All files|*.*" .FilterIndex = 1 If .ShowDialog() = Windows.Forms.DialogResult.OK Then counter = 0 writeline(0) = " Menu Items" + vbTab + "Qty" + vbTab + _ "Unit Cost" + vbTab + "Total Cost" writeline(1) = " ----------" + vbTab + "---" + vbTab + _ "---------" + vbTab + "----------" Dim y As Integer = 0 For x As Integer = 2 To 12 'writeline(2).PadLeft(5) writeline(x) = frmtodayscafe.filename(y) + vbTab + Format(frmtodayscafe.totalitemquantity(y)) + vbTab + _ FormatCurrency(frmtodayscafe.filename1(y)) + vbTab + vbTab + FormatCurrency(frmtodaysc
-
when I execute the follow code
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click Try With SaveFileDialog1 ' See the code demonstrating the OpenFileDialog control ' for examples using most properties, which are the same ' for both controls, for the most part. ' Add the default extension, if the user neglects to add an extension. ' The default is True. .AddExtension = True ' Check to verify that the output path actually exists. Prompt before ' creating a new file? Prompt before overwriting? ' The default is True. .CheckPathExists = True ' The default is False. .CreatePrompt = False ' The default is True. .OverwritePrompt = True ' The default is True. .ValidateNames = True ' The default is False. .ShowHelp = True ' If the user doesn't supply an extension, and if the AddExtension property is ' True, use this extension. The default is "". .DefaultExt = "txt" ' Prompt with the current file name if you've specified it. ' The default is "". '.FileName = filename3 '//filename3 = .FileName ' lblfilename.Text = SaveFileDialog1.FileName ' The default is "". .Filter = _ "Text files (*.txt)|*.txt|" & _ "All files|*.*" .FilterIndex = 1 If .ShowDialog() = Windows.Forms.DialogResult.OK Then counter = 0 writeline(0) = " Menu Items" + vbTab + "Qty" + vbTab + _ "Unit Cost" + vbTab + "Total Cost" writeline(1) = " ----------" + vbTab + "---" + vbTab + _ "---------" + vbTab + "----------" Dim y As Integer = 0 For x As Integer = 2 To 12 'writeline(2).PadLeft(5) writeline(x) = frmtodayscafe.filename(y) + vbTab + Format(frmtodayscafe.totalitemquantity(y)) + vbTab + _ FormatCurrency(frmtodayscafe.filename1(y)) + vbTab + vbTab + FormatCurrency(frmtodaysc
Try using String.Format to create a fixed length string which you would then write out to the file. Something like: myTXT = String.Format("{0,10:G}: {0,10:X}", value) write to disk myTXT Refer to http://msdn.microsoft.com/en-us/library/fht0f5be.aspx[^] http://idunno.org/archive/2004/07/14/122.aspx[^]
-
when I execute the follow code
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click Try With SaveFileDialog1 ' See the code demonstrating the OpenFileDialog control ' for examples using most properties, which are the same ' for both controls, for the most part. ' Add the default extension, if the user neglects to add an extension. ' The default is True. .AddExtension = True ' Check to verify that the output path actually exists. Prompt before ' creating a new file? Prompt before overwriting? ' The default is True. .CheckPathExists = True ' The default is False. .CreatePrompt = False ' The default is True. .OverwritePrompt = True ' The default is True. .ValidateNames = True ' The default is False. .ShowHelp = True ' If the user doesn't supply an extension, and if the AddExtension property is ' True, use this extension. The default is "". .DefaultExt = "txt" ' Prompt with the current file name if you've specified it. ' The default is "". '.FileName = filename3 '//filename3 = .FileName ' lblfilename.Text = SaveFileDialog1.FileName ' The default is "". .Filter = _ "Text files (*.txt)|*.txt|" & _ "All files|*.*" .FilterIndex = 1 If .ShowDialog() = Windows.Forms.DialogResult.OK Then counter = 0 writeline(0) = " Menu Items" + vbTab + "Qty" + vbTab + _ "Unit Cost" + vbTab + "Total Cost" writeline(1) = " ----------" + vbTab + "---" + vbTab + _ "---------" + vbTab + "----------" Dim y As Integer = 0 For x As Integer = 2 To 12 'writeline(2).PadLeft(5) writeline(x) = frmtodayscafe.filename(y) + vbTab + Format(frmtodayscafe.totalitemquantity(y)) + vbTab + _ FormatCurrency(frmtodayscafe.filename1(y)) + vbTab + vbTab + FormatCurrency(frmtodaysc
The pad function DO work, but you will get screwy results if you use tabs. If you need "ascii" tabular data, lined up perfectly, use ONLY spaces and padded fields to align your data. Do not use any tab characters.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...