程序运行后在一个标签内产生10个[1,100]的随机数,单击统计按钮后,在4个文本框内分别输出10个数中最大数,最小数,和,平均数。
急用!!谢谢!!!!!
第1个回答 2010-04-11
假设标签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
文本框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
第2个回答 推荐于2018-02-27
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本回答被提问者和网友采纳
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本回答被提问者和网友采纳
第3个回答 2010-04-11
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 max<b(a) then max=b(a)
if min>b(a) then min=b(a)
next
text1.text=max
text2.text=min
text3.text=sum
text4.text=aver
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 max<b(a) then max=b(a)
if min>b(a) then min=b(a)
next
text1.text=max
text2.text=min
text3.text=sum
text4.text=aver
第4个回答 2010-04-11
ty