VB数组元素的删除
用Array()给出数组a=array(1,2,3,4,5,6,7,8,9,10),现在把key值为10的元素删除,怎么写代码?按给的题目写代码,不要动态数组...
用Array()给出数组a=array(1,2,3,4,5,6,7,8,9,10),现在把key值为10的元素删除,怎么写代码?
按给的题目写代码,不要动态数组 展开
按给的题目写代码,不要动态数组 展开
2个回答
展开全部
Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Dim a As Variant
a = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
For i = 0 To UBound(a)
Text1.Text = Text1.Text & a(i) & " "
Next i
For i = 0 To UBound(a)
If a(i) = 10 Then
For j = i To UBound(a) - 1
a(j) = a(j + 1)
Next j
a(j) = a(i)
Exit For
End If
Next i
ReDim Preserve a(UBound(a) - 1)
For i = 0 To UBound(a)
Text2.Text = Text2.Text & a(i) & " "
Next i
End Sub
Text1.Text = ""
Text2.Text = ""
Dim a As Variant
a = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
For i = 0 To UBound(a)
Text1.Text = Text1.Text & a(i) & " "
Next i
For i = 0 To UBound(a)
If a(i) = 10 Then
For j = i To UBound(a) - 1
a(j) = a(j + 1)
Next j
a(j) = a(i)
Exit For
End If
Next i
ReDim Preserve a(UBound(a) - 1)
For i = 0 To UBound(a)
Text2.Text = Text2.Text & a(i) & " "
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询