|
-
Feb 7th, 2001, 03:29 PM
#1
Thread Starter
New Member
Hi I am a student who just started taking visual basic.
My latest project is an Olympic scoreboard, which has 5 judges labels and 10 cmd buttons. The project calls for the user to hit the first digit and that should be recorded in judge 1' s label and the next digit clicked should go in judge 2's lablel and so on.
So far all I can get is the digit to go in judge 1 lablel
Dim mintScore As Integer
Dim mintAverage As String
Dim mintScore2 As Integer
Private Sub cmdScore_Click(Index As Integer)
Dim NumPressed As Integer
NumPressed = Index
mintScore = 1 + mintScore
lblScore(0) = NumPressed
mintScore2 = lblScore(0) + lblScore(1) + lblScore(2) + lblScore(3) + lblScore(4)
lblAveragescore = mintScore2 / 4
End Sub
Private Sub cmdScore_KeyPress(Index As Integer, KeyAscii As Integer)
Dim NumPressed As Integer
NumPressed = Index
lblScore(1) = NumPressed
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 9
cmdScore(i).Caption = i + 1
Next i
For i = 0 To 4
lblJudge(i).Caption = "Judge" & i + 1
Next i
For i = 1 To 10
cmdScore(0) = i
Next i
End Sub
Please help because this is really frustrating.
-
Feb 7th, 2001, 03:41 PM
#2
Code:
Dim mintScore As Integer
Dim mintAverage As String
Dim mintScore2 As Integer
'I added this
Dim NextLabel as integer
Private Sub cmdScore_Click(Index As Integer)
Dim NumPressed As Integer
NumPressed = Index
mintScore = 1 + mintScore
'Added/Changed
lblScore(NextLabel) = NumPressed
'Keep track of next label to add to
NextLabel = NextLabel +1
mintScore2 = lblScore(0) + lblScore(1) + lblScore(2) + lblScore(3) + lblScore(4)
lblAveragescore = mintScore2 / 4
End Sub
Private Sub Form_Load()
'Added
NextLabel = 0
Dim i As Integer
For i = 0 To 9
cmdScore(i).Caption = i + 1
Next i
For i = 0 To 4
lblJudge(i).Caption = "Judge" & i + 1
Next i
For i = 1 To 10
cmdScore(0) = i
Next i
-
Feb 7th, 2001, 04:00 PM
#3
Hyperactive Member
Delete all the code in your form and replace it with:
Code:
Option Explicit
Option Compare Text
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 4
lblJudge(i).Caption = "Judge #" & i + 1
Next i
For i = 0 To 9
cmdScore(i).Caption = i + 1
Next i
End Sub
Private Sub cmdScore_Click(Index As Integer)
Dim i As Integer
Dim dblAverage As Double
Static sintJudge As Integer
If sintJudge > lblScore.Count - 1 Then
MsgBox "All Judges have scored."
Exit Sub
End If
lblScore(sintJudge).Caption = cmdScore(Index).Caption
dblAverage = 0
For i = 0 To sintJudge
dblAverage = dblAverage + Val(lblScore(i))
Next
sintJudge = sintJudge + 1
lblAverageScore.Caption = Format(dblAverage / sintJudge, "0.00")
End Sub
Run it, then see if you understand what's happening in the code and why it works.
-
Feb 7th, 2001, 04:04 PM
#4
Hyperactive Member
Ah, c'mon Cander. You couldn't indent it for him? hehheh.
Nilon, static variables are probably more advanced than you're class has gotten to, but maybe not. It's a good thing to learn, anyway. One hint for you regarding them...when they are first declared, numeric statics have a value of 0.
-
Feb 7th, 2001, 04:05 PM
#5
Im lazy!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|