华为荣耀4c截屏快捷键:vb 编程问题,急!!!!

来源:百度文库 编辑:高考问答 时间:2024/05/04 16:43:09
dim a(2) as integer,b() as integer
a(0)=1:a(1)=2:a(1)=2 '最大值为2,有2个对应坐标为1和2
如何处理使
redim b(1) :b(0)=1:b(1)=2
就是重新生成 b(对应坐标-1) 数组,每个b 元素对应一个 b 值?
就是已知某数组a,求出数组中最大的值(假设a(0)=465,a(1)=4554,a(2)=4554,最大的值是4554),并且把这些数组元素(既a(1)和a(2))放入另一个数组(b),b容量是数组元素的总数(a(1)和a(2)共2个最大值,b的容量为2个数.

有点明白了。
Dim a(2) As Integer, b() As Integer
Dim i As Integer
Dim max1 As Integer, max2 As Integer
Dim max_idx1 As Integer, max_idx2 As Integer

'以下两条语句是为了做到能比较负数大小
max1 = -65535
max2 = -65535

'检测第一个最大值
For i = 0 To UBound(a)
If max1 < a(i) Then
max_idx1 = i
max1 = a(i)
End If
Next
'检测第二个最大值
For i = 0 To UBound(a)
If max2 < a(i) And i <> max_idx1 Then '如果不与 max1 对应的索引重复
max_idx2 = i
max2 = a(i)
End If
Next

'赋值到 b
ReDim b(1)
b(0) = max_idx1
b(1) = max_idx2
MsgBox "b(0)=" & b(0) & ", b(1)=" & b(1)

是这样对吗?

你最好从新说明一下,我估计没几个人可以看懂
另一个数组的容量是数组元素的总数,那b与a不是一样多吗?还要redim吗?