Results 1 to 5 of 5

Thread: crazy

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    1

    Unhappy

    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.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    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.

  4. #4
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    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.

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Im lazy!
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width