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
1 Replies - 262 Views - Last Post: 29 September 2012 - 09:04 AM
#1
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.
Replies To: Input- Test Scores entered, Output- How Many were entered?
#2
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.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|