Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. writing to text file [modified] ... resolved

writing to text file [modified] ... resolved

Scheduled Pinned Locked Moved Visual Basic
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Engelkes
    wrote on last edited by
    #1

    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
    
    D D 2 Replies Last reply
    0
    • D Daniel Engelkes

      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
      
      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      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[^]

      1 Reply Last reply
      0
      • D Daniel Engelkes

        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
        
        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups