我正在尝试建立一个预订和支付系统,我目前有多个变量可以保存到文件中。我需要做的是添加付款到设置的bookingID,现在我已经对它进行了排序,以便将更改后的付款总额添加到文件中,但我无法将其删除旧的。因此,当它搜索文件时,它首先找到旧文件,而客户只支付50英镑,而不是最近支付100英镑的文件。那么我如何从文件中读取并做我需要处理的所有数据,然后删除那个单行数据然后我知道如何添加新数据。一位朋友提到使用数组但我试过在这里仔细观察,这让我很困惑。
提前致谢
上面有更多代码可以找到数据并显示它然后这是他们输入了他们想要添加的金额
Dim bookings As String
bookings = "E:\Grouse Lodge Bookings\Bookings.txt"
bookingidtemp = txtbookingid.Text
FileOpen(1, bookings, OpenMode.Input)
found = False
If temp = True Then
If found = False Then
Do Until found = True
Input(1, custname)
Input(1, address1)
Input(1, address2)
Input(1, cost)
Input(1, amount)
Input(1, startdate)
Input(1, enddate)
Input(1, postcode)
Input(1, bookingid)
Input(1, remaining)
If bookingidtemp = bookingid Then
txtname.Text = custname
txtaddress1.Text = address1
txtaddress2.Text = address2
txtcost.Text = cost
txtstartdate.Text = startdate
txtenddate.Text = enddate
txtpostcode.Text = postcode
txttopay.Text = remaining
found = True
FileClose(1)
Else
End If
Loop
End If
If found = False Then
MsgBox("Booking not found, please try again")
FileClose(1)
Else
If found = True Then
FileOpen(1, bookings, OpenMode.append)
custname = txtname.Text
address1 = txtaddress1.Text
address2 = txtaddress2.Text
cost = txtcost.Text
amount = txtpaid.Text
startdate = txtstartdate.Text
enddate = txtenddate.Text
postcode = txtpostcode.Text
bookingid = txtbookingid.Text
cost = txtcost.Text
amount = txtpaid.Text
paying = remaining - amount
remaining = paying
amount = cost - remaining
WriteLine(1, custname, address1, address2, cost, amount, startdate, enddate, postcode, bookingid, remaining)
FileClose(1)
MsgBox("Payment added")
答案 0 :(得分:0)
也许......
Public Sub rml(ByVal path As String, ByVal ln As Integer)
Dim tb As New TextBox
tb.Text = My.Computer.FileSystem.ReadAllText(path)
Dim str As New List(Of String)
Dim i As Integer = 0
For Each l In tb.Lines
str.Add(tb.Lines(i))
i += 1
Next
str.RemoveAt(ln - 1)
tb.Text = ""
For Each h In str
tb.Text = tb.Text & h & vbNewLine
Next
Dim writer As New System.IO.StreamWriter(path)
writer.Write(tb.Text)
writer.Close()
End Sub
示例:rml("C:\Users\User1\Desktop\TextEx.txt", 5)
将删除文本文件的第五行" TextEx"