Visual Basic~ 请教
设置了20个textbox让用户输入数字,怎么求这20个数的最大值,最小值,第2大值和第2小值,请告诉我详细点,我是菜鸟,特别是求第2大值和第2小值的过程,非常感谢
既然是用戶從 Textbox 裏輸入的, 就不要另外寫過程判斷了
在 TextBox 的 Change 或 LostFocus 事件裏直接判斷就好了,
第二大和第二小.都是一样..只要找到最大值..然后再减去下一个数..如果差是最小的话..那这个数就跟最大数最接近..也就是第二大...第二小也是一样..
Private Sub Command1_Click()
Dim i As Integer
Dim intNum(5) As Integer
For i = 0 To 4
intNum(i) = Text1(i).Text
Next
Dim Max As Integer, Min As Integer
Max = intNum(0)
Min = intNum(0)
For i = 1 To 4
If (intNum(i) > Max) Then Max = intNum(i)
If (intNum(i) < Min) Then Min = intNum(i)
Next
Dim twomax As Integer
Dim temp As Integer
temp = Max - intNum(0)
For i = 0 To 4
If (Max - intNum(i) < temp) And (Max - intNum(i) <> 0) Then
twomax = intNum(i)
temp = Max - intNum(i)
End If
Next
Print "最大是:"; Max
Print "最小是:"; Min
Print "第二大是:"; twomax
End Sub
'最二小,,你自己求.