如何在文本文件中的行旁边附加新的字符串数据行和新的“索引号”

问题描述

我想使用流编写器或vb.net中的任何方法将新行以及新的索引号附加到文本文件中(我正在使用2015版) 我设法将其保存,但只保存了第一个文本框。 这是我到目前为止的内容:@H_502_1@

    Dim outputFile As IO.StreamWriter
    Dim filePath As String = "PCPT2Database.txt"
    Dim intNewNo() As Integer = {}
    Dim intCount As Integer = 0
    Dim currentRow() As String

    Dim intLoop As Integer

    Using MyReader As New Microsoft.VisualBasic.FileIO.textfieldparser(filePath)
        MyReader.TextFieldType = FileIO.FieldType.Delimited
        MyReader.SetDelimiters(",")

        While Not MyReader.EndOfData
            Try
                currentRow = MyReader.ReadFields()

                ReDim Preserve intNewNo(intCount)

                intNewNo(intCount) = currentRow(0)

                intCount = +1

            Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                MsgBox("line" & ex.Message & " Its not valid.")

            End Try
        End While
    End Using

    For intLoop = 0 To intCount + 1

    Next




    If IO.File.Exists(filePath) = True Then
        outputFile = IO.File.AppendText(filePath)

        outputFile.WriteLine(intNewNo(intLoop),txtName.Text,txtSurname.Text,mtbcell.Text,txtEmail.Text)
        'intNewNo(intLoop),MessageBox.Show("Save Successful")
        outputFile.Close()

        MessageBox.Show("Add another record","Cancel",MessageBoxButtons.OKCancel,MessageBoxIcon.@R_752_4045@ion)

        txtName.Clear()
        txtSurname.Clear()
        mtbcell.Clear()
        txtEmail.Clear()
    Else
        MessageBox.Show(filePath,".txt not found.",_
                        MessageBoxButtons.RetryCancel,MessageBoxIcon.@R_752_4045@ion)
    End If
End Sub

解决方法

删除代码顶部的<html> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> <div class='nav flex-row'> <div class="nav flex-column nav-pills" id="v-pills-tab" style='width: 100px' role="tablist" aria-orientation="vertical"> <a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true">Home</a> <a class="nav-link" id="v-pills-profile-tab" data-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="false">Profile</a> <a class="nav-link" id="v-pills-messages-tab" data-toggle="pill" href="#v-pills-messages" role="tab" aria-controls="v-pills-messages" aria-selected="false">Messages</a> <a class="nav-link" id="v-pills-settings-tab" data-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</a> </div> <div class="tab-content" id="v-pills-tabContent"> <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">test1</div> <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">test2</div> <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">test3</div> <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">test4</div> </div> </div> </html>声明,并按如下方式使用:

outputFile

但是您的代码需要优化(有点?)(: