急 急 急!!! 求VB 几个基础代码

来源:百度知道 编辑:UC知道 时间:2024/06/05 11:56:07
这学期开了VB课 什么都没学会 求VB的 求和代码,,最大值代码,,最小值代码,,平均分代码,,排序代码。。

正学追加分

一般这些问题都是用数组的
比如定义一个数组,10个元素:
dim su(9) as single
'求和:
function he(su() as single) as single
for i=0 to ubound(su)
he=he+su(i)
next
end function

'最大值:
function ma(su() as single) as single
ma=su(0)
for i=1 to ubound(su)
if ma<su(i) then ma=su(i)
next
end function

'最小值:
function mi(su() as single) as single
mi=su(0)
for i=1 to ubound(su)
if mi>su(i) then mi=su(i)
next
end function

'平均值:
function sv(su() as single) as single
for i=0 to ubound(su)
he=he+su(i)
next
sv=he/i
end function

'排序
sub paixu(su() as single)
n=ubound(su)
for i=0 to n-1
for j=i+1 to n
if su(i)>su(j) thfen
t=su(i) '交换
su(i)=su(j)
su(j)=t
endif