The file is being created and it is somewhat working. It works okay if you have the program open and enter like 3, 4, 1. It's supposed to subtract these from 10. It does so, saying that you have 2 hours left. But once it's shut down and you check the file, it is only holding the last number entered, not all of them. This leave me with a few questions:

How can I make the file hold all of the values, even after the program is shut down?

I need to make a Reset button to clear the file out. How do I make this happen?

Here's this section of code so far:

Private Sub submitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles submitBtn.Click

      SaveTextToFile(timeSpentTxt.Text, "C:\Documents and Settings\All Users\Documents\College-C\IT\VB.Net\Assignments\Semester Project\ATV Records\runningTally.txt")

      'var declarations
      Dim todaysTime As Decimal = Val(timeSpentTxt.Text)
      runningTally += todaysTime
      timeRemaining = 10 - runningTally
      timeRemainingOutputLbl.Text = timeRemaining
      lifetime += runningTally
      lifetimeHrsOutputLbl.Text = lifetime

   End Sub Private Sub submitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles submitBtn.Click

      SaveTextToFile(timeSpentTxt.Text, "C:\Documents and Settings\All Users\Documents\College-C\IT\VB.Net\Assignments\Semester Project\ATV Records\runningTally.txt")

      'var declarations
      Dim todaysTime As Decimal = Val(timeSpentTxt.Text)
      runningTally += todaysTime
      timeRemaining = 10 - runningTally
      timeRemainingOutputLbl.Text = timeRemaining
      lifetime += runningTally
      lifetimeHrsOutputLbl.Text = lifetime

   End Sub

I would do one of the following:

Change this line from:

SaveTextToFile(timeSpentTxt.Text, "C:\Docum...

To this to save ALL the entered values:

'Create this as a Form Level Global
Private RunningTally As List(Of Double)

'Change the code from
'runningTally += todaysTime

'To
runningTally.Add(todaysTime)


'And then change this code
'timeRemaining = 10 - runningTally

'To
Dim SaveVal as string

timeRemaining = 10
For each Item as Double In runningTally
   timeRemaining -= Item 
   SaveVal += Item & ";"
Next

SaveTextToFile(SaveVal, "C:\Docum...

When reloading the text file you will need to re-add the data to the runningTally.Add(FROMFILE) using an array and the line FROMFILE.Split(";") to separate the values


Or this to save the lifetimeHrsOutputLbl:

SaveTextToFile(lifetimeHrsOutputLbl.Text, "C:\Docum...

Or this to save the timeRemaining:

SaveTextToFile(timeRemaining , "C:\Docum...

Okay, I've been working on this and have become stuck on a few parts. I can't figure out how to subtract the running total from 10. I also can't figure out how to make the time remaining label have a value when the form loads. Any tips on this would be SO much appreciated.

Imports System.IO

Public Class atvRecords

   'Public var declaration
   Private timeRemaining As Decimal = 10
   Private lifetime As Decimal = 11
   Private runningTally As List(Of Double)
   Private timeLeft As List(Of Double)

   Private Sub atvRecords_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles MyBase.Load

      'if time left less than 2, messagebox
      If Val(lifetimeHrsOutputLbl.Text) <= 2 And Val(lifetimeHrsOutputLbl.Text) > 1 Then
         MessageBox.Show("Two hours or less of ride time remains before an oil change is needed.", _
         "Oil change needed soon.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
      End If

      'if time left less than 1, messagebox
      If Val(lifetimeHrsOutputLbl.Text) <= 1 And Val(lifetimeHrsOutputLbl.Text) Then
         MessageBox.Show("One hour or less of ride time remains before an oil change is needed.", _
         "Oil change needed soon.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
      End If

      'if time left less than 0, messagebox
      If Val(lifetimeHrsOutputLbl.Text) <= 0 Then
         MessageBox.Show("WARNING: Do NOT ride any more until an oil change is performed!", _
         "OIL CHANGE NEEDED IMMEDIATELY!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
      End If

   End Sub

   Public Function SaveTextToFile(ByVal strData As String, _
   ByVal FullPath As String, Optional ByVal ErrInfo As String = "") As Boolean

      Dim bAns As Boolean = False
      Dim objReader As StreamWriter

      Try
         objReader = New StreamWriter(FullPath)
         objReader.Write(strData)
         objReader.Close()
         bAns = True
      Catch Ex As Exception
         ErrInfo = Ex.Message
      End Try
      Return bAns
   End Function

   Private Sub submitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles submitBtn.Click

      'REQUIRE PASSWORD!

      'clear time spent label
      timeSpentTxt.Text = ""


      'write to file for Running Tally
      Dim todaysTime As Double = Val(timeSpentTxt.Text)
      runningTally.Add(todaysTime)
      Dim tempTotal As String = 0

      For Each Item As Double In runningTally
         timeRemaining -= Item
         tempTotal += Item & ";"
      Next

      SaveTextToFile(tempTotal, _
            "C:\Documents and Settings\All Users\Documents\College-C\IT\VB.Net\Assignments\Semester Project\ATV Records\runningTally.txt")


      'calculate time remaining
      timeRemaining = 10 - tempTotal


      'calculate lifetime hours
      lifetimeHrsOutputLbl.Text = lifetime
      lifetime += tempTotal

   End Sub

   Private Sub resetBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles resetBtn.Click

      'REQUIRE PASSWORD!!
      runningTally = 0
      timeRemaining = 10

   End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.