关于VB编程题
用ab = Array(25, 36, 78, 25, 78, 34, 26, 89, 25, 34, 89, 34, 63, 150, 40, 25, 46, 36, 150, 40),并且输出这个数组里有什么数,重复的输一个(用VB编程)谢谢帮忙
追问:要是不用UBound,能做吗?
用ab = Array(25, 36, 78, 25, 78, 34, 26, 89, 25, 34, 89, 34, 63, 150, 40, 25, 46, 36, 150, 40),并且输出这个数组里有什么数,重复的输一个(用VB编程)谢谢帮忙
追问:要是不用UBound,能做吗?
答案:Private Sub Command1_Click()
Dim ab As Variant
Dim f As Boolean
ab = Array(25, 36, 78, 25, 78, 34, 26, 89, 25, 34, 89, 34, 63, 150, 40, 25, 46, 36, 150, 40)
For i = 0 To UBound(ab)
f = True
For j = 0 To i - 1
If ab(j) = ab(i) Then
f = False
Exit For
End If
Next j
If f Then
Print ab(i)
End If
Next i
End SubPrivate Sub Command1_Click()
Me.AutoRedraw = True
ab = Array(25, 36, 78, 25, 78, 34, 26, 89, 25, 34, 89, 34, 63, 150, 40, 25, 46, 36, 150, 40)
For i = 1 To UBound(ab)
For j = UBound(ab) To i + 1 Step -1
If ab(i) = ab(j) Then c = ab(i): ab(i) = ab(j): ab(j) = b
Next j, i
Print ab(1);
n = ab(1)
For i = 2 To UBound(ab)
If n <> ab(i) Then Print ab(i);
Next i
End Sub