《求助!急!》请教高手一个菜鸟的问题 程序调试 在线等
输入N个数到数组中,找出其中最小的数和最大的数,并将两者互换位置。(数组元素的个数N用Inputbox函数输入)运行结果参考如下窗体:单击窗体,运行结果如下所示:
数组的初始值:
1 7 6 -99 2
交换后数组的值:
1 -99 6 7 2
我的代码如下,但是运行后显示空白 应该怎么修改啊 小妹谢谢各位高手了
Private Sub Form_Load()
On Error GoTo errhandler
Dim arr1() As Double, biggest As Integer, smallest As Integer, temp As Double, arrtxt As String, arrtxt1 As String
numofarray = InputBox("请输入数组的个数")
ReDim arr1(Val(numofarray) - 1)
For i = 0 To Val(numofarray) - 1
arr1(i) = InputBox("请输入第" & i + 1 & "个数")
arrtxt = arrtxt & " " & arr1(i)
biggest = IIf(arr1(i) > biggest, i, biggest)
smallest = IIf(arr1(i) < smallest, i, smallest)
Next i
temp = arr1(biggest)
arr1(biggest) = arr1(smallest)
arr1(smallest) = temp
For Each i In arr1
arrtxt1 = arrtxt1 & " " & i
Next
Print "数组的初始值:"
Print arrtxt
Print "交换后数组的值:"
Print arrtxt1
Exit Sub
errhandler:
MsgBox "error"
End Sub