传入数组,传出最大和最小值的函数Private Sub Swap(intList() As Integer, ByRef intMax As Integer, ByRef intMin As Integer) Dim intIndex As Integer intMax = intList(0) intMin = intList(0) For intIndex = 0 To UBound(intList) - 1 If intList(intIndex) > intMax Then intMax = intList(intIndex) End If If intList(intIndex) < intMin Then intMin = intList(intIndex) End If Next End Sub
dim a (1 to 10) as integer dim temp as integer for i=1 to a.lenth if temp>a(i) temp=a(i) next print temp
如果是非浮点数,数据都大于0,而且不是很大可以试试不排序的办法(字节型的最好,呵呵) dim data(4) as byte'这里放置五个要排序的数据dim d() as byte dim i as long for i=0 to 4 redim preserve d(data(i)) d(data(i))=data(i) next for i=0 to ubound(d) if d(i)>0 then debug.print d(i) exit for end if next
Dim intIndex As Integer
intMax = intList(0)
intMin = intList(0) For intIndex = 0 To UBound(intList) - 1
If intList(intIndex) > intMax Then
intMax = intList(intIndex)
End If
If intList(intIndex) < intMin Then
intMin = intList(intIndex)
End If
Next
End Sub
dim temp as integer
for i=1 to a.lenth
if temp>a(i)
temp=a(i)
next
print temp
dim data(4) as byte'这里放置五个要排序的数据dim d() as byte
dim i as long
for i=0 to 4
redim preserve d(data(i))
d(data(i))=data(i)
next
for i=0 to ubound(d)
if d(i)>0 then
debug.print d(i)
exit for
end if
next