I doing the common 'enter scores, total, average and display" problem as I'm learning VB (see screenshot). It works great with the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim score As Integer = score
Static scoreTotal As Integer = scoreTotal
Static numberOfScores As Integer
Dim averageScore As Decimal

numberOfScores += 1
score = TextBox1.Text
scoreTotal = scoreTotal + TextBox1.Text
averageScore = (scoreTotal / numberOfScores)

Me.TextBox1.Text = score
Me.TextBox2.Text = scoreTotal
Me.TextBox3.Text = numberOfScores
Me.TextBox4.Text = averageScore

But then I have to code the button that displays the individual scores. I know how to make the message box come up, but I can't call up all the individual scores that have been entered. I know this doesn't work:

'Dim scoresString As String
'For i As Integer = 0 To scores.Length - 1
'scores() &= scores(9).ToString
'scores(i) = i

How do I get VB to save the scores as score(0), score(1), etc.? This has been driving me nuts for two days, and any help would really be appreciated. You can probably tell I'm new at this...

Attachments ddd.jpg 43.22 KB
7 Years
Discussion Span
Last Post by TomW

You need to create an Array variable. Also you should turn on Option Strict & Option Explicit to have the design environment show you some mistake you are making with not explicitly converting your values to the proper datatypes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.