假设标签Label1
文本框Text1 Text2 Text3 Text4
统计按钮Command1
窗体代码
Option Explicit
Private Sub Command1_Click()
Dim Vs() As Long, Ls() As String, fo As Long, Vc As Long
Dim Max As Long, Min As Long, e As Double,t as long
ReDim Vs(Len(Label1))
Ls = Split(Label1, vbCrLf)
For fo = 0 To UBound(Ls)
If IsNumeric(Ls(fo)) Then
Vs(Vc) = Val(Ls(fo))
If Vc = 0 Then Max = Vs(0): Min = Vs(0)
If Max < Vs(Vc) Then Max = Vs(Vc)
If Min > Vs(Vc) Then Min = Vs(Vc)
Vc = Vc + 1
End If
Next
If Vc Then
ReDim Preserve Vs(Vc - 1)
For fo = 0 To Vc - 1
e = e + Vs(fo) / Vc
t=t+vs(fo)
Next
End If
Text1 = "最大" & Max
Text2 = "最新" & Min
Text3="和"& t
Text4 = "平均" & Round(e, 6)
End Sub
Private Sub Form_Load()
Dim fo As Long
Randomize Timer
For fo = 1 To 10
Label1 = Label1 & Rand(1, 100) & vbCrLf
Next
Label1.Height = TextHeight("") * 10
End Sub
Function Rand(Left As Long, Right As Long) As Long
Rand = Left + (Right - Left) * Rnd
End Function
Dim a(10) As Integer
Min = 100: Max = 1
For i = 1 To 10
Randomize
a(i) = Int(Rnd(1) * 100 + 1)
Label1.Caption = Label1.Caption & Str(a(i))
Sum = Sum + a(i)
If a(i) > Max Then Max = a(i)
If a(i) < Min Then Min = a(i)
Next
Text1 = Max
Text2 = Min
Text3 = Sum
Text4 = Sum / 10
dim a&,b&()
dim max&
dim min&
dim sum&
dim aver&
for a=1 to 10
b(a)=int(rnd*100)+1
sum=sum+b(a)
label1.caption=label1.caption & trim(str(b(a)))
next
aver=sum/10
max=b(1)
min=b(1)
for a=1 to 10
if maxif min>b(a) then min=b(a)
next
text1.text=max
text2.text=min
text3.text=sum
text4.text=aver
ty