1 Replies - 838 Views - Last Post: 29 September 2012 - 09:04 AM Rate Topic: -----

#1 cheyennebrown  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-September 12

Input- Test Scores entered, Output- How Many were entered?

Posted 29 September 2012 - 08:31 AM

User should enter an unknown number of test scores in an InputBox and I save the scores in a sequential access file. The btnCount click event should display in a MessageBox the number of scores stored in the file. I have the first part entered correctly but the scores are not showing in the sequential access file. Did I do it wrong or am I missing something?? Then I am confused as to how to add the numbers that are in the stored file once I finally get them to store correctly.


 Public Class frmMain
    Private intSub As Integer
    Private strInputScore As String
    Private decScore() As Decimal = {}
    Private decTotal() As Decimal

       Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        'display total number of test scores

        Const strPROMPT As String = "Enter a test score. Click Cancel to end."
        
        'declare a StreamWriter variable
        Dim outFile As IO.StreamWriter
        'open the file for append
        outFile = IO.File.AppendText("scores.txt")

        'get a score
        strInputScore = InputBox(strPROMPT, "ReDim")

        Do While strInputScore <> String.Empty
            'add element to the array
            ReDim Preserve decScore(intSub)
            'store score in the array
            Decimal.TryParse(strInputScore, decScore(intSub))
            'update the subscript
            intSub += 1
            'get the next score
            strInputScore = InputBox(strPROMPT, "ReDim")
            outFile.WriteLine(InputBox(strPROMPT, "ReDim"))
        Loop

        outFile.Close()

    End Sub

    Private Sub btnCount_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCount.Click

        Dim inFile As IO.StreamReader
        Dim decNumber As Decimal
        If IO.File.Exists("scores.txt") = True Then
            'open the file for input
            inFile = IO.File.OpenText("scores.txt")

            Do Until inFile.Peek = -1
                decNumber = inFile.ReadLine
                decNumber += decTotal(intSub)
                    
            Loop
            MessageBox.Show("Total number of scores: ", "Scores",
                               MessageBoxButtons.OK,
                               MessageBoxIcon.Information)
            inFile.Close()

        End If
    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Input- Test Scores entered, Output- How Many were entered?

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 767
  • Joined: 19-October 11

Re: Input- Test Scores entered, Output- How Many were entered?

Posted 29 September 2012 - 09:04 AM

What is InputBox? Put breakpoint to your lines 18 and 28, and step through the code to see, if strInputScore gets the value you enter.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1