VB 菜鸟问题,高手进来下!!急!

来源:百度知道 编辑:UC知道 时间:2024/07/04 02:46:32
Dim numbers(1 To 10) As Integer

Dim total As Integer

Dim max, min, avg As Integer

total = 0

' find the maximum and minimum number
' and calculate the average without caling any functions
For i = 1 To 10
numbers(i) = lstNum.List(i - 1)
Next i
' Or alternatively, we can write maximum and minimum
' functions to get the job done

max = maximum(numbers)
min = minimum(numbers)
avg = average(numbers)

txtMax.Text = Str(max)
txtMin.Text = Str(min)
txtAverage.Text = Str(avg)
' find all the prime numbers in the array
Call findPrimeNumbers(numbers())
End Sub
Function maximum(n() As Integer) As Integer
Dim max As Integer
Dim i As Integer
max = n(1)
For i = 1 To 10
If max < n(i) Then

不可以,你在调用的时候他会认为你这个是表达式,但是找不到变量就会出错,所以在调用数组做为参数,你只要输入它的数组名,计算机自动会帮你做的.反而你+的是"数组名()"他会认为还有另个子程序,会寻找,找不到就会提示你或给你默认值,这样就达不到你想要的效果了