VB评委打分提问!!!!!!急啊!!
现在的问题是点 评委人数 要让他限制最大人数的值 代码再下面 比如点击出来一个输入框 输入5而他的最大值就被限制为5 现在一共有10个,简单的说就是把下面的9改为输入框中的数字 而那个8是随限制人数-1的 然后根据限制人数去掉最大值和最小值算平均分 誰知道Private Sub Command1_Click()
Dim a(9) As Single, i As Integer, sum As Single, ave As Single, max As Single, min As Single
min = Val(Text1(0).Text)
For i = 0 To 9
a(i) = Val(Text1(i).Text)
sum = sum + a(i)
If a(i) > max Then max = a(i)
If a(i) < min Then min = a(i)
Next
ave = (sum - max - min) / 8
Label2.Caption = ave
Label3.Caption = max
Label4.Caption = min
End Sub
--------------------编程问答-------------------- 如果只是求最大,最小和乘下分值的平均值,那么你的程序已经实现了。
有可能是我没有理解你的意思,你说的不是太清楚。 --------------------编程问答-------------------- Private Sub Command1_Click()
Dim a(9) As Single, i As Integer, sum As Single, ave As Single, max As Single, min As Single
min = Val(Text1(0).Text)
Dim Amount As Integer
Amount = InputBox("请输入评委人数")
For i = 0 To Amount
a(i) = Val(Text1(i).Text)
sum = sum + a(i)
If a(i) > max Then max = a(i)
If a(i) < min Then min = a(i)
Next
ave = (sum - max - min) / (Amount - 1)
Label2.Caption = ave
Label3.Caption = max
Label4.Caption = min
End Sub --------------------编程问答-------------------- 同意2楼的做法 只要录入当前的评委数就可以了 --------------------编程问答--------------------
--------------------编程问答-------------------- 多考虑不同的情况,比如有时是去掉一个最高/低分,有时是多个。
Private Sub Command1_Click()
Dim a() As Single, i As Integer, sum As Single, ave As Single, max As Single, min As Single
Dim intNumbers as Integer
'评委人数
intNumbers = val(txtNumbers.text)-1
redim a(intNumbers) as Single
min = Val(Text1(0).Text)
For i = 0 To intNumbers
a(i) = Val(Text1(i).Text)
sum = sum + a(i)
If a(i) > max Then max = a(i)
If a(i) < min Then min = a(i)
Next
ave = (sum - max - min) / intNumbers
Label2.Caption = ave
Label3.Caption = max
Label4.Caption = min
End Sub
补充:VB , 基础类