Private Sub btnBatch_Click(sender As Object, e As EventArgs) Handles btnBatch.Click
' This button Calculates the current value then updates the value and array
' And also creates a new file to work with
lstOutput.Items.Add(" Updated Current Value ")
' Increase every record's price field by 10%
'Create a new CSV record for each record (showing the increase)
' and write it to the Temp file.
' Do list all updated records in the Output
' if item number matches the updatItem value, Dont write to the Temp File,
' Set found to true and list in the listbox
' If item number DOESNT match the updatedItem Valu, THen write the record
' to the Temp file just as it was read in
Dim sr As IO.StreamReader = IO.File.OpenText("Assets.txt")
Dim sw As IO.StreamWriter = IO.File.CreateText("Temp.txt")
Dim found As Boolean = False
Dim itemCurrentValue As Double = data(5)
Dim purchasePrice As Double = data(4)
Dim itemLife As Double = data(6)
Dim depreciationDate As Date = data(7)
lastDay = DateAdd("d", -1, DateSerial(Year(Now), Month(Now), 1))
If depreciationDate < lastDay Then
If itemCurrentValue <> 0 Then
newValue = ItemsCurrentValue(purchasePrice, itemLife, itemCurrentValue)
depreciationDate = Today.ToString("d")
sw.WriteLine(data(0) & "," & data(1) & "," & data(2) & "," & data(3) & _
"," & purchasePrice.ToString("C2") & "," & newValue.ToString("C2") _
& "," & itemLife & "," & depreciationDate)
lstOutput.Items.Add(data(0) & "," & data(1) & "," & data(2) & "," & data(3) & _
"," & purchasePrice.ToString("C2") & "," & newValue.ToString("C2") _
& "," & itemLife & "," & depreciationDate)
'Delete the 'Original' file
IO.File.Delete("Assets.txt")
' Make "temp.txt" the new original file
IO.File.Move("Temp.txt", "Assets.txt")