Visual basic 2010 問題

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

參考資料： 自己