輸入5位學生的5個科目
算出個人總分
總平均和各科平均
有一個Command
有3個CheckBox
分別是總分,總平均,各科平均
算出來的東西 要出現在text裡面
↓↓↓ 做到這樣就不會了= =(新手新手)
Private Sub Command1_Click()
Dim a, b, c, d, e, f, g As Single
a = Val(InputBox("請輸入國文值"))
b = Val(InputBox("請輸入國文值"))
c = Val(InputBox("請輸入國文值"))
d = Val(InputBox("請輸入國文值"))
e = Val(InputBox("請輸入國文值"))
Text1.Text = f
score = InputBox("請輸入段考成績:")
f = (a + b + c + d + e) / 5
g = a + b + c + d + e
Print "平均": f
Print "總分": g
End Sub
2006-12-11 15:25:59 · 2 個解答 · 發問者 BB 1 in 電腦與網際網路 ➔ 程式設計
請在表單上放入Text1,Text2,Text3,Command1,Check1,Check2,Check3,將Text1,Text2,Text3的屬性MultiLine設為True,將下列程式寫入。
Dim a(5), b(5), c(5), d(5), e(5), total(1 To 5), avg(5) As Double
Private Sub Command1_Click()
If Check1.Value = 1 Then
Text1 = "個人總分" & vbCrLf & a(0) & total(1) & vbCrLf & b(0) & total(2) & vbCrLf & c(0) & total(3) & vbCrLf & d(0) & total(4) & vbCrLf & e(0) & total(5)
Else
Text1 = ""
End If
If Check2.Value = 1 Then
Text2 = "總平均" & vbCrLf & avg(0)
Else
Text2 = ""
End If
If Check3.Value = 1 Then
Text3 = "各科平均" & vbCrLf & "第一科" & avg(1) & vbCrLf & "第二科" & avg(2) & vbCrLf & "第三科" & avg(3) & vbCrLf & "第四科" & avg(4) & vbCrLf & "第五科" & avg(5)
Else
Text3 = ""
End If
End Sub
Private Sub Form_Load()
a(0) = InputBox("第一位姓名")
a(1) = Val(InputBox("第一科"))
a(2) = Val(InputBox("第二科"))
a(3) = Val(InputBox("第三科"))
a(4) = Val(InputBox("第四科"))
a(5) = Val(InputBox("第五科"))
b(0) = InputBox("第二位姓名")
b(1) = Val(InputBox("第一科"))
b(2) = Val(InputBox("第二科"))
b(3) = Val(InputBox("第三科"))
b(4) = Val(InputBox("第四科"))
b(5) = Val(InputBox("第五科"))
c(0) = InputBox("第三位姓名")
c(1) = Val(InputBox("第一科"))
c(2) = Val(InputBox("第二科"))
c(3) = Val(InputBox("第三科"))
c(4) = Val(InputBox("第四科"))
c(5) = Val(InputBox("第五科"))
d(0) = InputBox("第四位姓名")
d(1) = Val(InputBox("第一科"))
d(2) = Val(InputBox("第二科"))
d(3) = Val(InputBox("第三科"))
d(4) = Val(InputBox("第四科"))
d(5) = Val(InputBox("第五科"))
e(0) = InputBox("第五位姓名")
e(1) = Val(InputBox("第一科"))
e(2) = Val(InputBox("第二科"))
e(3) = Val(InputBox("第三科"))
e(4) = Val(InputBox("第四科"))
e(5) = Val(InputBox("第五科"))
total(1) = a(1) + a(2) + a(3) + a(4) + a(5)
total(2) = b(1) + b(2) + b(3) + b(4) + b(5)
total(3) = c(1) + c(2) + c(3) + c(4) + c(5)
total(4) = d(1) + d(2) + d(3) + d(4) + d(5)
total(5) = e(1) + e(2) + e(3) + e(4) + e(5)
avg(0) = (total(1) + total(2) + total(3) + total(4) + total(5)) / 5
avg(1) = (a(1) + b(1) + c(1) + d(1) + e(1)) / 5
avg(2) = (a(2) + b(2) + c(2) + d(2) + e(2)) / 5
avg(3) = (a(3) + b(3) + c(3) + d(3) + e(3)) / 5
avg(4) = (a(4) + b(4) + c(4) + d(4) + e(4)) / 5
avg(5) = (a(5) + b(5) + c(5) + d(5) + e(5)) / 5
End Sub
2006-12-11 18:29:50 · answer #1 · answered by 水月 6 · 0⤊ 0⤋
VB 的優點在於 GUI 所以應該多利用它
底下是螢幕設計
[ ] 文字格 (Text)
{ } 按鈕 Command
( ) 標籤 Label
< > 確認盒 Check
"____" 祇是為了對齊, 你可以不必畫
================================================
學生_ 科目1 科目2 科目3 科目4 科目5_總分__總平均
[S1(0)][S1(1)][S1(2)][S1(3)][S1(4)][S1(5)] [S1(6)] [S1(7)]
[S2(0)][S2(1)][S2(2)][S2(3)][S2(4)][S2(5)] [S2(6)] [S2(7)]
[S3(0)][S3(1)][S3(2)][S3(3)][S3(4)][S3(5)] [S3(6)] [S3(7)]
[S4(0)][S4(1)][S4(2)][S4(3)][S4(4)][S4(5)] [S4(6)] [S4(7)]
[S5(0)][S5(1)][S5(2)][S5(3)][S5(4)][S5(5)] [S5(6)] [S5(7)]
平均_ [A(1)]_[A(2)]_[A(3)]_[A(4)]_[A(5)]
================================================
Private Sub Command1_Click()
Dim i as Integer
Dim avg(5) as Single
Dim total(5) as Single
Dim subject(5) as Single
If Check1.Value = 1 Then
For i = 1 to 5
total(i) = 0
Next i
For i = 1 to 5
total(1) = total(1) + Val(S1(i))
total(2) = total(2) + Val(S2(i))
total(3) = total(3) + Val(S3(i))
total(4) = total(4) + Val(S4(i))
total(5) = total(5) + Val(S5(i))
Next i
S1(6) = total(1)
S2(6) = total(2)
S3(6) = total(3)
S4(6) = total(4)
S5(6) = total(5)
Else
S1(6) = ""
S2(6) = ""
S3(6) = ""
S4(6) = ""
S5(6) = ""
End If
If Check2.Value = 1 Then
S1(7) = total(1)/5
S2(7) = total(2)/5
S3(7) = total(3)/5
S4(7) = total(4)/5
S5(7) = total(5)/5
Else
S1(7) = ""
S2(7) = ""
S3(7) = ""
S4(7) = ""
S5(7) = ""
End If
If Check3.Value = 1 Then
For i = 1 to 5
subject(i) = 0
Next i
For i = 1 to 5
subject(i)=subject(i)+Val(S1(i))+Val(S2(i))+Val(S3(i))+Val(S4(i))+Val(S5(i))
Next i
A(1) = subject(1)/5
A(2) = subject(2)/5
A(3) = subject(3)/5
A(4) = subject(4)/5
A(5) = subject(5)/5
Else
A(1) = ""
A(2) = ""
A(3) = ""
A(4) = ""
A(5) = ""
End If
2006-12-12 07:08:03 · answer #2 · answered by JJ 7 · 0⤊ 0⤋