locked
Comma Delimited Text File

    Question

  • I'm having some problems with comma delimited reading and writing. 

    The text file will look something like this:

    "Name",  "ID#",  "Grade",  "Class"
    "Bob Jones", 1, "A-", "Introduction to CS"
    "Sarah Johnson", 2, "B+", "Data Structures"
    "Sam Smith", 3, "A", "Visual Basic"


    The program should display like this:

      


    I think I'm going about this entirely wrong.  Right now I'm just working on reading the file, creating the proper spaces and removing the comma's and parentheses.

    Imports System.IO 
    Public Class Form1 
     
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
     
            Dim fileName As String 
            fileName = ("D:\Data.txt"
            If File.Exists(fileName) Then 
                Try 
                    Dim stream As New StreamReader(fileName) 
                    txtOutput.Text &= stream.ReadToEnd() 
                Catch ex As System.IO.IOException 
                    MessageBox.Show("Error reading from file""File Error", _ 
                       MessageBoxButtons.OK, MessageBoxIcon.Error
                End Try 
            End If 
        End Sub 
    End Class 

    Wednesday, November 26, 2008 11:17 PM

Answers

  • Dim FileLines() As String = File.ReadAllLines("C:\Temp\Test.csv")
    For I As Integer = 0 To FileLines.Length - 1
        FileLines(I) = FileLines(I).Replace(
    """", "")
    Next
    File.WriteAllLines("C:\Temp\Test.csv", FileLines)

    • Marked as answer by Xingwei Hu Tuesday, December 02, 2008 6:15 AM
    Friday, November 28, 2008 6:54 AM
  • Code within Form_Closing is garbage now, you can remove whole handler, until you have reason to use it. I can't understand what is happening with your ListView, it is not possible what you say you observed. Check Dock & Anchor values in propertyBox of your ListView in designer... but if there is anything, your code does not resize ListView on data change...and never else ... so only thing which can manipulate its size is Dock and Anchor ptoperties...
    • Marked as answer by Xingwei Hu Tuesday, December 02, 2008 6:16 AM
    Saturday, November 29, 2008 11:31 AM
  • Why do you want the quotes on the fields in the test file?  Can't you use the CSV format?
    Remove all the ListView1 UI code and set the ListView the way you want it in the designer.

    • Marked as answer by Xingwei Hu Tuesday, December 02, 2008 6:14 AM
    Saturday, November 29, 2008 12:45 PM

All replies

  • Hi JynxRD,

    Looks to me like you are doing a programming course on VB.Net at college or university?

    It doesn't matter to me if you are, although if you are I wish you success!! :-)

    Here is a clue.

    Use the ReadLine method for the StreamReader.

    Use the String.Split method to split the lines on the comma CHARacter.


    Regards,

    John

    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    Thursday, November 27, 2008 2:19 AM
  • I started reading a book.  And now I'm doing the online course the book offers.  I don't need the work done for me lol so I don't want you to think I'm looking for that.  I'm just looking for some examples that will clearly show me the way.
    Thursday, November 27, 2008 2:37 AM
  • Not doing something right..

    Imports System.IO 
    Public Class Form1 
     
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
     
            Dim fileName As String 
            fileName = ("D:\Data.txt"
            If File.Exists(fileName) Then 
                Try 
                    Dim stream As New StreamReader(fileName) 
                    Dim sLine As String = stream.ReadLine 
     
                    While Not sLine Is Nothing 
                        stream.ReadLine.Split(","c) 
                        txtOutput.Text = stream.ReadLine 
     
                        sLine = stream.ReadLine() 
                    End While 
     
                Catch ex As System.IO.IOException 
                    MessageBox.Show("Error reading from file""File Error", _ 
                       MessageBoxButtons.OK, MessageBoxIcon.Error
                End Try 
            End If 
        End Sub 
    Thursday, November 27, 2008 3:07 AM
  • Tried this too.  Not sure how to do this.

        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
     
     
            Dim reader As New StreamReader("D:\Data.txt"
            Dim data As String() 
            data = reader.ReadLine().Split(","
            txtOutput.Text = data 
     
        End Sub 

    Thursday, November 27, 2008 3:50 AM
  • Ok so I did this.  However, it only displays the first line, and it adds that row on separate lines.  So where as I want :

    Bob Jones 1 A- Introduction to CS
    Sarah Johnson 2 B+ Data Structures
    Sam Smith 3 A Visual Basic

    It instead gives me :

    Bob
    Jones
    1
    A-
    Introduction
    To
    CS


    Public Class Form1 
     
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
     
            Me.LoadCommaDelimetedTextFileIntoListBox("D:\Data.txt"
     
        End Sub 
     
     
        Private Sub LoadCommaDelimetedTextFileIntoListBox(ByVal filePath As String
     
            ' Declare a variable named theTextFieldParser of type TextFieldParser. 
            Dim theTextFieldParser As FileIO.TextFieldParser 
     
            ' Call the My feature's OpenTextFieldParser method passing in a file path. 
            ' Assign the resulting TxtFileParser object to theTextFieldParser variable. 
            theTextFieldParser = My.Computer.FileSystem.OpenTextFieldParser(filePath) 
     
            ' Set TextFieldParser object's TextFieldType property to Delimited. 
            theTextFieldParser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited 
     
            ' Configure delimiters to handle a comma delimited text file: 
            ' Set TextFieldParser object's Delimiter's property to a string array 
            ' containing one element with the value ",". 
            theTextFieldParser.Delimiters = New String() {","
     
            ' Declare a variable named currentRow of type string array. 
            Dim currentRow() As String 
     
            ' While the end of file has not been reached.... 
            While Not theTextFieldParser.EndOfData 
                Try 
                    ' Read the fields on the current line 
                    ' and assign them to the currentRow array variable. 
                    currentRow = theTextFieldParser.ReadFields() 
     
                    ' Declare a variable named currentField of type String. 
                    Dim currentField As String 
     
                    ' Use the currentField variable to loop 
                    ' through fields in the currentRow. 
                    For Each currentField In currentRow 
                        ' Add the the currentField (a string) 
                        ' to the demoLstBox items. 
                        Me.demoListBox.Items.Add(currentField) 
                    Next 
                Catch malFormLineEx As Microsoft.VisualBasic.FileIO.MalformedLineException 
                    MessageBox.Show("Line " & malFormLineEx.Message & "is not valid and will be skipped.""Malformed Line Exception"
                Catch ex As Exception 
                    MessageBox.Show(ex.Message & " exception has occurred.""Exception"
                Finally 
                    ' If successful or if an exception is thrown, 
                    ' close the TextFieldParser. 
                    theTextFieldParser.Close() 
                End Try 
            End While 
     
     
        End Sub 

    Thursday, November 27, 2008 5:33 AM
  • Hey. Try this
      Structure Record  
        Dim a$, b$, c%, d#  
        Sub New(ByVal k$, ByVal l$, ByVal m%, ByVal n#)  
          Me.a = k  
          Me.b = l  
          Me.c = m  
          Me.d = n  
        End Sub 
      End Structure 
     
      Sub Main()  
        Dim ret As New List(Of Record)  
        Dim a$, b$, c%, d# 'columns  
        Dim ff% = FreeFile()  
        FileOpen(ff, "C:\a.txt", OpenMode.Input)  
        Do 
          Input(ff, a) : Input(ff, b) : Input(ff, c) : Input(ff, d)  
          ret.Add(New Record(a, b, c, d))  
        Loop Until EOF(ff)  
        FileClose(ff) 

    for such file:
    "1", "2", 3, 4.5  
    "hello", "world", 1, 5.25 


    Regards, Matt
    This contributor is MSDN testing bot, using BabelFish translator, passive NN "Thread integrator" and Google's VBCContextSearch api to help you resolving threads, if you want to improve it, just react to its posts. Your MSDN team :)
    Thursday, November 27, 2008 5:46 AM
  •  You can also use DAC tools for it, so that you get Database-Like interface, rather then low level shown before
      Structure Record  
        Dim a$, b$, c%, d#  
        Sub New(ByVal rdr As OleDb.OleDbDataReader)  
          Me.a = rdr.GetString(0)  
          Me.b = rdr.GetInt32(1)  
          Me.c = rdr.GetString(2)  
          Me.d = rdr.GetString(3)  
        End Sub 
      End Structure 
     
     
      Sub Main()  
        Dim ret As New List(Of Record)  
        Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='I:\DB';Extended Properties='text;HDR=Yes;FMT=Delimited'")  
        Dim cmd As New OleDb.OleDbCommand("Select * From myTable", con)  
        con.Open()  
        Dim rdr As OleDb.OleDbDataReader = cmd.ExecuteReader  
        While rdr.Read  
          ret.Add(New Record(rdr))  
        End While 
        rdr.Close()  
        cmd.Dispose()  
        con.Close() 


    what will work, if you have directory "I:\DB" and file "myTable" there which looks completely as that you shown at start of thread
    This contributor is MSDN testing bot, using BabelFish translator, passive NN "Thread integrator" and Google's VBCContextSearch api to help you resolving threads, if you want to improve it, just react to its posts. Your MSDN team :)
    Thursday, November 27, 2008 6:11 AM
  • Would that only work with the existing file though because I'm going to need to be able to add more records to it and display the entire thing as it grows.
    Thursday, November 27, 2008 3:45 PM
  • Consider using a ListView control:

    Imports System.IO

    Public Class Form1

      Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        With ListView1

          Dim Lines(.Items.Count) As String

          Dim I, J As Integer

          Lines(0) = .Columns(0).Text

          For J = 1 To .Columns.Count - 1

            Lines(0) += "," & .Columns(J).Text

          Next

          For I = 1 To .Items.Count

            Lines(I) = .Items(I - 1).Text

            For J = 1 To .Columns.Count - 1

              Lines(I) += "," & .Items(I - 1).SubItems(J).Text

            Next

          Next

        End With

      End Sub

      Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim FileLines() As String = File.ReadAllLines("C:\Temp\Test.csv")

        With ListView1

          .SuspendLayout()

          .View = View.Details

          .Columns.Clear()

          .Items.Clear()

          .Scrollable = True

          Dim I, J, TextWidth As Integer

          Dim Lines(FileLines.Length - 2)() As String

          Dim Headers() As String = FileLines(0).Split(","c)

          Dim Fields As Integer = Headers.Length

          Dim MaxWidth(Fields - 1) As Integer

          For J = 0 To Fields - 1

            TextWidth = TextRenderer.MeasureText(Headers(J), .Font).Width + 6

            If TextWidth > MaxWidth(J) Then MaxWidth(J) = TextWidth

          Next

          For I = 0 To Lines.Length - 1

            Lines(I) = FileLines(I + 1).Split(","c)

            For J = 0 To Fields - 1

              TextWidth = TextRenderer.MeasureText(Lines(I)(J), .Font).Width + 6

              If TextWidth > MaxWidth(J) Then MaxWidth(J) = TextWidth

            Next

          Next

          .Width = 0

          For J = 0 To Fields - 1

            .Columns.Add(Headers(J), MaxWidth(J), HorizontalAlignment.Left)

            .Width += MaxWidth(J)

          Next

          .Width += 4

          For I = 0 To Lines.Length - 1

            .Items.Add(Lines(I)(0))

            For J = 1 To Fields - 1

              .Items(I).SubItems.Add(Lines(I)(J))

            Next

          Next

          .ResumeLayout()

        End With

      End Sub

    End Class
    Thursday, November 27, 2008 3:50 PM
  • Wow. It was fight to get it work, but finally :)
    Here is complete sample of using ADO (OLE DB) above CSV, and having 3-tier app with interactive DataGridView (CSV -> MEMORY DB -> UI -> BUTTON -> LOAD / UPDATE). No requirements :)

    Public Class Form1  
      Dim gview As New Windows.Forms.DataGridView  
      Dim panel1 As New Windows.Forms.GroupBox  
      WithEvents btnAdd As New Windows.Forms.Button  
      WithEvents btnSave As New Windows.Forms.Button  
      WithEvents btnLoad As New Windows.Forms.Button  
     
      Dim image As New DataTable  
      Dim adapter As New OleDb.OleDbDataAdapter  
     
      'Const TableHeader$ = "Name,Age" - i tried everything here to get it working with (,)  
      'Const ConnString$ = "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _  
      '                    "Source=C:\007\;Extended " & _  
      '                    "Properties=""text;HDR=Yes;FMT=Delimited(,)"""  
      Const TableHeader$ = "Name;Age" 
      Const ConnString$ = "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _  
                          "Source=C:\007\;Extended " & _  
                          "Properties=""text;HDR=Yes;FMT=Delimited""" 
      Sub New()  
        InitializeComponent()  
     
        panel1.Text = "EditBox" 
        panel1.Height = 64  
        panel1.Dock = DockStyle.Top  
        panel1.Name = "Panel1" 
     
        gview.Dock = DockStyle.Fill  
        gview.Name = "DataGridView1" 
     
        btnAdd.Name = "Button1" 
        btnAdd.Text = "Add" 
        btnAdd.Dock = DockStyle.Right  
     
        btnSave.Name = "Button2" 
        btnSave.Text = "Save" 
        btnSave.Dock = DockStyle.Left  
     
        btnLoad.Name = "Button3" 
        btnLoad.Text = "Load" 
        btnLoad.Dock = DockStyle.Left  
     
        panel1.Controls.Add(btnAdd)  
        panel1.Controls.Add(btnSave)  
        panel1.Controls.Add(btnLoad)  
     
        Me.Controls.Add(gview)  
        Me.Controls.Add(panel1)  
     
        image.Columns.Add("Name"GetType(String))  
        image.Columns.Add("Age"GetType(Byte))  
     
        gview.DataSource = image  
     
        Call Install()  
        Call PrepareAdapter()  
        Me.Text = "Hello three-tier data world" 
      End Sub 
      Sub Install()  
        If IO.Directory.Exists("C:\007") = False Then IO.Directory.CreateDirectory("C:\007")  
        If IO.File.Exists("C:\007\DemoCSV007.csv") = False Then _  
           IO.File.AppendAllText("C:\007\DemoCSV007.csv", TableHeader)  
      End Sub 
      Sub PrepareAdapter()  
        With adapter  
          .SelectCommand = New OleDb.OleDbCommand("Select * From DemoCSV007.csv")  
          .InsertCommand = New OleDb.OleDbCommand("Insert Into DemoCSV007.csv(Name, Age) Values(?, ?)")  
          .InsertCommand.Parameters.Add("Name", OleDb.OleDbType.VarChar, 25, "Name")  
          .InsertCommand.Parameters.Add("Age", OleDb.OleDbType.UnsignedTinyInt, 1, "Age")  
          .UpdateCommand = New OleDb.OleDbCommand("Update DemoCSV007.csv Set Age=? Where Name=?")  
          .UpdateCommand.Parameters.Add("Age", OleDb.OleDbType.UnsignedTinyInt, 1, "Age")  
          .UpdateCommand.Parameters.Add("Name", OleDb.OleDbType.VarChar, 25, "Name")  
          .DeleteCommand = New OleDb.OleDbCommand("Delete From DemoCSV007.csv Where Name=?")  
          .DeleteCommand.Parameters.Add("Name", OleDb.OleDbType.VarChar, 25, "Name")  
        End With 
      End Sub 
     
      Private Sub btnAdd_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnAdd.Click  
        Dim name$, age%  
        name = InputBox("Name")  
        age = InputBox("Age")  
        Dim row As DataRow = Me.image.NewRow  
        row.Item("Name") = name : row.Item("Age") = age  
        Me.image.Rows.Add(row)  
      End Sub 
     
      Private Sub btnSave_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnSave.Click  
        Dim con As New OleDb.OleDbConnection(ConnString)  
        adapter.SelectCommand.Connection = con  
        con.Open()  
        adapter.DeleteCommand.Connection = con  
        adapter.InsertCommand.Connection = con  
        adapter.UpdateCommand.Connection = con  
        adapter.SelectCommand.Connection = con  
        adapter.Update(image)  
        con.Close()  
      End Sub 
     
      Private Sub btnLoad_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnLoad.Click  
        Dim con As New OleDb.OleDbConnection(ConnString)  
        adapter.SelectCommand.Connection = con  
        con.Open()  
        adapter.Fill(image)  
        con.Close()  
      End Sub 
     
      Private Sub Form1_FormClosing(ByVal sender As ObjectByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing  
        'uninstall  
        If MsgBox("Uninstall?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question) = MsgBoxResult.Yes Then _  
         FileIO.FileSystem.DeleteDirectory("C:\007", FileIO.DeleteDirectoryOption.DeleteAllContents)  
      End Sub 
    End Class 
     


    I always dreamed of designing without designer :)

    Regards, Matt
    • Edited by konikula Thursday, November 27, 2008 8:26 PM code update
    Thursday, November 27, 2008 7:36 PM
  • If someone has idea how to modify connection string in order to work with comma separated csv, without migrating from OleDb to Odbc namespace, I am one ear... I can't work it out, even if many people show snippets with "(,)" behind "Delimited" in connection string, I did not found way to change TableHeader to work with such definition...:(
    This contributor is MSDN testing bot, using BabelFish translator, passive NN "Thread integrator" and Google's VBCContextSearch api to help you resolving threads, if you want to improve it, just react to its posts. Your MSDN team :)
    Thursday, November 27, 2008 8:24 PM
  • JohnWein,

    How would you go about both adding the ability to remove the " " parenthesis.

    Alternatively,

    I have 5 text box's for First Name, Last Name, ID, Grade, Class. That I need to write to the file as : "Bob Jones", 1, "A-", "Introduction to CS"
    Friday, November 28, 2008 1:47 AM
  • Dim FileLines() As String = File.ReadAllLines("C:\Temp\Test.csv")
    For I As Integer = 0 To FileLines.Length - 1
        FileLines(I) = FileLines(I).Replace(
    """", "")
    Next
    File.WriteAllLines("C:\Temp\Test.csv", FileLines)

    • Marked as answer by Xingwei Hu Tuesday, December 02, 2008 6:15 AM
    Friday, November 28, 2008 6:54 AM
  • Ok worked great.  Still having an issue writing to this to match the original comma delimited quotation.
    Friday, November 28, 2008 6:08 PM
  • Try to return to my snippet #1, FileOpen(Input) & Input(#) is compatible with FileOpen(Output) & WriteLine(#).
    1 FileOpen(ff, "C:\a.txt", OpenMode.Output)  
    2 WriteLine(ff, "A""B"c, 2.5#, cInt(14)) 

    like this :)

    Regards, Matej
    This contributor is MSDN testing bot, using BabelFish translator, passive NN "Thread integrator" and Google's VBCContextSearch api to help you resolving threads, if you want to improve it, just react to its posts. Your MSDN team :)
    Friday, November 28, 2008 6:24 PM
  • I came up with this.  However it doesn't add it to the file correctly.

        Private Sub Button3_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button3.Click 
            Dim FILE_NAME As String = "D:\Data.txt" 
            Dim i As Integer 
            Dim aryText(4) As String 
     
            aryText(0) = TextBox1.Text 
            aryText(1) = TextBox2.Text 
            aryText(2) = TextBox3.Text 
            aryText(3) = TextBox4.Text 
            aryText(4) = TextBox5.Text 
     
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True
     
            For i = 0 To 4 
                objWriter.WriteLine(aryText(i)) 
            Next 
     
            objWriter.Close() 
            MsgBox("Text Appended to the File"
        End Sub 

    Friday, November 28, 2008 6:49 PM
  • I got it to also add commas and quotes by adding them around (aryText(i)) but they don't show up right.  I'm not sure what I'm doing wrong.
    Friday, November 28, 2008 8:42 PM
  • I am not sure if you were trying to use my advice? If so, don't mismatch functions of Microsoft.VisualBasic namespace to functions System.IO ... StreamWriter.WriteLine is totally different conception to FileOpen : WriteLine. If you are completing something different, I am sorry for confusing post ;). If not, just type only THREE lines.. from fileOpen to fileClose >o<

    Regards, Matej
    This contributor is MSDN testing bot, using BabelFish translator, passive NN "Thread integrator" and Google's VBCContextSearch api to help you resolving threads, if you want to improve it, just react to its posts. Your MSDN team :)
    Friday, November 28, 2008 11:29 PM
  • Well this is what I have currently.  And it works now.  However I have 2 things that I'm trying to fix within THIS code.

    Now. After adding the "write" code in Button3, I now get this error in Form1_Closing :

    Lines(0) = .Columns(0).Text
    - InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index

    Secondly. I want the listview to stay a width of 450, 204. However it changes depending on the length of the text or the amount of things in the listview. How can I make 450, 204 fixed.


    Imports System.IO 
    Public Class Form1 
     
        Private Sub Form1_FormClosing(ByVal sender As ObjectByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing 
     
            With ListView1 
                Dim Lines(.Items.Count) As String 
                Dim I, J As Integer 
                Lines(0) = .Columns(1).Text 
                For J = 1 To .Columns.Count - 1 
                    Lines(0) += "," & .Columns(J).Text 
                Next 
                For I = 1 To .Items.Count 
                    Lines(I) = .Items(I - 1).Text 
                    For J = 1 To .Columns.Count - 1 
                        Lines(I) += "," & .Items(I - 1).SubItems(J).Text 
                    Next 
                Next 
            End With 
        End Sub 
     
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
     
            Dim FileLines() As String = File.ReadAllLines("D:\Data.txt"
            For I As Integer = 0 To FileLines.Length - 1 
                FileLines(I) = FileLines(I).Replace("""", ""
            Next 
            With ListView1 
                .SuspendLayout() 
                .View = View.Details 
                .Columns.Clear() 
                .Items.Clear() 
                .Scrollable = True 
     
                Dim I, J, TextWidth As Integer 
                Dim Lines(FileLines.Length - 2)() As String 
                Dim Headers() As String = FileLines(0).Split(","c) 
                Dim Fields As Integer = Headers.Length 
                Dim MaxWidth(Fields - 1) As Integer 
                For J = 0 To Fields - 1 
                    TextWidth = TextRenderer.MeasureText(Headers(J), .Font).Width + 53 
                    If TextWidth > MaxWidth(J) Then MaxWidth(J) = TextWidth 
                Next 
                For I = 0 To Lines.Length - 1 
                    Lines(I) = FileLines(I + 1).Split(","c) 
                    For J = 0 To Fields - 1 
                        TextWidth = TextRenderer.MeasureText(Lines(I)(J), .Font).Width + 53 
                        If TextWidth > MaxWidth(J) Then MaxWidth(J) = TextWidth 
                    Next 
                Next 
                .Width = 0 
                For J = 0 To Fields - 1 
                    .Columns.Add(Headers(J), MaxWidth(J), HorizontalAlignment.Left) 
                    .Width += MaxWidth(J) 
                Next 
                .Width += 4 
                For I = 0 To Lines.Length - 1 
                    .Items.Add(Lines(I)(0)) 
                    For J = 1 To Fields - 1 
                        .Items(I).SubItems.Add(Lines(I)(J)) 
                    Next 
                Next 
                .ResumeLayout() 
            End With 
        End Sub 
     
        Private Sub Button3_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button3.Click 
            Dim FILE_NAME As String = "D:\Data.txt" 
            Dim aryText(4)  As String  
     
            aryText(0) = TextBox1.Text 
            aryText(1) = TextBox2.Text 
            aryText(2) = TextBox3.Text 
            aryText(3) = TextBox4.Text 
            aryText(4) = TextBox5.Text 
     
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True
     
            objWriter.WriteLine(String.Format("""{0} {1}"", ""{2}"", ""{3}"", ""{4}""", aryText)) 
     
            objWriter.Close() 
            MsgBox("Added"
        End Sub 
    End Class 
     

    Saturday, November 29, 2008 3:21 AM
  • Code within Form_Closing is garbage now, you can remove whole handler, until you have reason to use it. I can't understand what is happening with your ListView, it is not possible what you say you observed. Check Dock & Anchor values in propertyBox of your ListView in designer... but if there is anything, your code does not resize ListView on data change...and never else ... so only thing which can manipulate its size is Dock and Anchor ptoperties...
    • Marked as answer by Xingwei Hu Tuesday, December 02, 2008 6:16 AM
    Saturday, November 29, 2008 11:31 AM
  • Why do you want the quotes on the fields in the test file?  Can't you use the CSV format?
    Remove all the ListView1 UI code and set the ListView the way you want it in the designer.

    • Marked as answer by Xingwei Hu Tuesday, December 02, 2008 6:14 AM
    Saturday, November 29, 2008 12:45 PM
  • Hm, John, as this is practicing, I would consider necessities of this or that format important.

    Regards, Matej
    Saturday, November 29, 2008 3:01 PM
  •  Don't you mean that it gets horizontal scrollbar, so it appears as it was resizing?
    Regards, MaTT
    Posting you abusive right now, and all of your posts!
    Monday, December 08, 2008 3:00 PM