發問時間: 電腦與網際網路程式設計 · 8 年前

Visual basic 2010 問題

第6章的習題

6-2跟6-3

6-2要建立可輸入參賽者名稱跟評審給分

目前個人打出

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim score(4) As Integer

Dim num, i, sum As Integer

Dim inval As Integer

Dim a1, a2, a3, a4, a5 As Integer

Label2.Text = ""

num = 0

Do

inval = InputBox("請輸入參賽者名稱")

If Trim(inval) = "" Then

Continue Do

Else

a1 = InputBox("請輸入甲給分")

If Trim(a1) = "" Then

Continue Do

Else

a2 = InputBox("請輸入乙給分")

If Trim(a2) = "" Then

Continue Do

Else

a3 = InputBox("請輸入丙給分")

If Trim(a3) = "" Then

Continue Do

Else

a4 = InputBox("請輸入丁給分")

If Trim(a4) = "" Then

Continue Do

Else

a5 = InputBox("請輸入戊給分")

If Trim(a5) = "" Then

End If

Continue Do

End If

End If

End If

End If

End If

Loop Until num > 4

For i = 0 To 4

Label2.Text &= "" & i + 1 & score(i) & vbTab

sum += score(i)

Next

End Sub.

然後就卡關了 不知道是哪裡出錯 想求解答

之前有成功做出可以顯示出參賽者名稱跟分數 可是沒辦法顯示多人

只會顯示最後一位 而且好像有不少淺再問題 可是已經忘記上次是怎麼打了

1 個解答

評分
  • 8 年前
    最佳解答

    這個程式我

    1.找不到記錄使用名稱的地方

    2.分數加總的地方

    3.sum不知道用在哪裡,之後在哪邊秀出

    想想後,變成這樣

    Dim score(4) As Integer

    Dim num, i As Integer

    'sum As Integer

    Dim inval(4) As String

    Dim a1, a2, a3, a4, a5 As Integer

    Label2.Text = ""

    num = 0

    Do

      inval(num) = InputBox("請輸入參賽者名稱")

      If Trim(inval(num)) = "" Then

        Continue Do

      Else

        a1 = InputBox("請輸入甲給分")

        If Trim(a1) = "" Then

          Continue Do

        Else

          a2 = InputBox("請輸入乙給分")

          If Trim(a2) = "" Then

            Continue Do

          Else

            a3 = InputBox("請輸入丙給分")

            If Trim(a3) = "" Then

              Continue Do

            Else

              a4 = InputBox("請輸入丁給分")

              If Trim(a4) = "" Then

                Continue Do

              Else

                a5 = InputBox("請輸入戊給分")

                If Trim(a5) = "" Then

                  Continue Do

                End If

                score(num) = a1 + a2 + a3 + a4 + a5

                num = num + 1

              End If

            End If

          End If

        End If

      End If

    Loop Until num > 4

    For i = 0 To 4

      Label2.Text &= inval(i) & "總分" & score(i) & " "

      'sum += score(i)

    Next

    參考資料: 自己
還有問題?馬上發問,尋求解答。