数组元素移动位置,用Dim声明数组s并利用Array函数给数组s赋值,由文本框输入要移动的位置数,通过单选按钮
展开全部
Private Sub Form_Load()
'创建一个数组
Dim a(9) As Integer
'初始化数组
Dim i As Integer
For i = 0 To UBound(a)
a(i) = i + 1
Next
'插入操作
Dim temp1 As Integer, temp2 As Integer '定义2个临时变量
temp1 = a(UBound(a)) '临时变量1初始值设置为最后一个值
For i = 0 To UBound(a)
temp2 = a(i)
a(i) = temp1
temp1 = temp2
Next
'测试结果
Dim str As String
str = ""
For i = 0 To UBound(a)
str = str & "第" & i + 1 & "项: " & a(i) & vbCrLf
Next
Debug.Print str
End Sub
'创建一个数组
Dim a(9) As Integer
'初始化数组
Dim i As Integer
For i = 0 To UBound(a)
a(i) = i + 1
Next
'插入操作
Dim temp1 As Integer, temp2 As Integer '定义2个临时变量
temp1 = a(UBound(a)) '临时变量1初始值设置为最后一个值
For i = 0 To UBound(a)
temp2 = a(i)
a(i) = temp1
temp1 = temp2
Next
'测试结果
Dim str As String
str = ""
For i = 0 To UBound(a)
str = str & "第" & i + 1 & "项: " & a(i) & vbCrLf
Next
Debug.Print str
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询