Each new order takes the order number form the txt file, and apprends by 1 to create the new order number.
However I cant seem to find how to read the last line of the txt file, so I do not get duplicate order numbers?
for example
My text file has the following order numbers:
3403
3404
My code for the text file is as follows
Expand|Select|Wrap|Line Numbers
- Dim orderNumStreamReader As IO.StreamReader
- Dim orderNumStreamWriter As IO.StreamWriter
- Dim orderNum As Integer
- Dim newOrderNum As Integer
- If IO.File.Exists("OrderNum.txt") Then
- orderNumStreamReader = IO.File.OpenText("OrderNum.txt")
- Else
- MessageBox.Show("File Does not Exist", "OrderNumber", MessageBoxButtons.OK, _
- MessageBoxIcon.Information)
- End If
- orderNum = orderNumStreamReader.ReadLine()
- orderNumStreamReader.Close()
- newOrderNum = orderNum + 1
- If IO.File.Exists("OrderNum.txt") Then
- orderNumStreamWriter = IO.File.AppendText("OrderNum.txt")
- Else
- MessageBox.Show("File Does not Exist", "OrderNumber", MessageBoxButtons.OK, _
- MessageBoxIcon.Information)
- End If
- orderNumStreamWriter.WriteLine(newOrderNum)
- orderNumStreamWriter.Close()
Now when I run my app, it reads the first line of the order number and appends that, giving me duplicate order numbers.