我正在创建一个像商店一样的程序。店主创建一个新产品,并写下名称,价格,GTIN-8代码和可用产品的数量。当客户使用GTIN-8代码购买物品并指定数量时,程序应更新文本文件并更改剩余库存量。例如。如果有50个表并且用户购买了10个,则文本文件应该更新,然后显示40个。
我的代码
Dim aLine As String = ""
Dim theField As String = ""
Dim aChar As Char
findstring = IO.File.OpenText("Stock.txt")
Do Until findstring.EndOfStream
aLine = findstring.ReadLine()
theField = ""
GtinField = ""
NameField = ""
PriceField = ""
For i = 0 To aLine.Length() - 1
aChar = aLine(i)
If aChar <> "," Then
theField = theField + aChar
Else
If GtinField = "" Then
GtinField = theField
ElseIf NameField = "" Then
NameField = theField
End If
theField = ""
End If
Next
PriceField = theField
If GtinField = txtGTIN.Text Then
receipt.lstreceipt.Items.Add(GtinField & Space(3) & NameField & Space(2) & txtquantity.Text & Space(2) & PriceField & Space(2) & "£" & PriceField * txtquantity.Text)
finalPrice = finalPrice + (PriceField * txtQuantity.Text)
End If
theField = ""
Loop
findstring.Close()
End Sub