刚学VB求教个简单的问题,从文本框中输入数据求平均值该怎么处理
从text中读取用空格分开的数据存入数组中并求平均值该怎么操作?主要是不知道怎么生成那个数组并知道长度,我习惯C语言那种求和除以个数那种方式...
从text中读取用空格分开的数据存入数组中并求平均值该怎么操作?主要是不知道怎么生成那个数组并知道长度,我习惯C语言那种求和除以个数那种方式
展开
3个回答
展开全部
Private Sub Command1_Click()
Dim a
a = Split(Text1.Text)
Dim s As Single
For i = LBound(a) To UBound(a)
s = s + a(i)
Next i
MsgBox s / (UBound(a) + 1)
End Sub
Private Sub Form_Load()
Text1.Text = "22 11 33"
End Sub
调试通过的,别忘了采纳
Dim a
a = Split(Text1.Text)
Dim s As Single
For i = LBound(a) To UBound(a)
s = s + a(i)
Next i
MsgBox s / (UBound(a) + 1)
End Sub
Private Sub Form_Load()
Text1.Text = "22 11 33"
End Sub
调试通过的,别忘了采纳
展开全部
dim Arr
Arr=split(TEXT1.TEXT," ")
s=0
for i= 0 to Ubound(Arr)-1
S=S+VAL(Arr(i)
next i
A=S/ubound(Arr)
Arr=split(TEXT1.TEXT," ")
s=0
for i= 0 to Ubound(Arr)-1
S=S+VAL(Arr(i)
next i
A=S/ubound(Arr)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-09-16 · 知道合伙人教育行家
关注
展开全部
处理方法如下:
Private Function AverageA(A As Variant) As Double
Dim s As Double
s = 0
For i = 0 To UBound(A)
s = s + Val(A(i))
Next
If i <> 0 Then AverageA = s / i Else AverageA = 0
End Function
Private Sub Command1_Click()
Dim A
A = Split(Trim(Text1.Text))
Text2.Text = AverageA(A)
End Sub
Private Function AverageA(A As Variant) As Double
Dim s As Double
s = 0
For i = 0 To UBound(A)
s = s + Val(A(i))
Next
If i <> 0 Then AverageA = s / i Else AverageA = 0
End Function
Private Sub Command1_Click()
Dim A
A = Split(Trim(Text1.Text))
Text2.Text = AverageA(A)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询