工程form1中的代码如下:
Option Base 1
Dim b() As Integer
Dim a() As Integer
Private Sub Form_Load()
 Form1.AutoRedraw = True
 ReDim a(10)
 For i = 1 To 5
  a(i) = i * 2
  Print a(i);
 Next i
End Sub
Private Sub Command1_Click()
 Static b As Integer, x As Integer
   b = b + 1
 If b Mod 2 <> 0 Then
    x = Val(InputBox("请输入要插入的数:"))
    Call fact1(a(), x)
 End IfEnd Sub
  module1中的代码如下:
   Option Base 1
Public Sub fact1(b() As Integer, y As Integer)
 For i = LBound(b) To UBound(b)
  If y < b(i) Then Exit For
Next i
 ReDim Preservea(UBound(b) + 1)
  For j = UBound(b) - 1 To i Step -1
    b(j + 1) = b(j)
  Next j
 b(j) = y
 End Sub
  但是没有结果输出,请问这是怎么会事????

解决方案 »

  1.   

    把form1的AUTOREDRAW属性设置为TRUE试
      

  2.   

    ReDim Preservea(UBound(b) + 1)
    -----------------
    ReDim Preserve a(UBound(b) + 1)
    少个空格
      

  3.   

    Command1_Click里没有打印,专门写一个SUB来打印数组的数据:工程form1中的代码如下:Option Base 1
    Dim b() As Integer
    Dim a() As Integer
    Private Sub PrintArr(arr() As Integer)
    Me.Cls
    Dim i As Long
    For i = LBound(arr) To UBound(arr)
    Print arr(i);
    Next
    End Sub
    Private Sub Form_Load()
    Form1.AutoRedraw = True
    ReDim a(10)
    For i = 1 To 10
    a(i) = i * 2
    Next i
    PrintArr a
    End Sub
    Private Sub Command1_Click()
    Static b As Integer, x As Integer
    b = b + 1
    If b Mod 2 <> 0 Then
    x = Val(InputBox("请输入要插入的数:"))
    Call fact1(a(), x)
    PrintArr a
    End If
    End Sub
    module1中的代码如下:Option Base 1
    Public Sub fact1(b() As Integer, y As Integer)
    For i = LBound(b) To UBound(b)
    If y < b(i) Then Exit For
    Next i
    Debug.Print i
    ReDim Preserve b(UBound(b) + 1)
    For j = UBound(b) - 1 To i Step -1
    b(j + 1) = b(j)
    Next j
    b(j + 1) = y
    End Sub