我写了一个递规算法,对十个数字进行全排列,运行代码后,结果出来了,可是点击FORM后,vb 就无法运行了,请高手指点。急急急!
代码如下:
Option Explicit
Dim i%
'用分治法排列十个整数
Private Sub Command1_Click()
Static data(9) As Integer
If i < 10 Then
data(i) = Val(Text1.Text)
Command1.Caption = "下一个"
Text1.Text = ""
i = i + 1
If i = 10 Then Command1.Caption = "排序"
Else
Command1.Caption = "结束"
If i = 10 Then Call Sort(data, 0, 9): i = 11
End If
End Sub
'全排列
Public Sub Sort(list() As Integer, k%, m%)
Dim j%
Dim strings$
If k > m Then
For j = 0 To m
strings = " " + Str$(list(j))
Print strings
Print
Next
Else
For j = k To m
Text2.Text = j
Call Swap(list(k), list(j))
Call Sort(list(), k + 1, m)
Call Swap(list(k), list(j))
Next
End If
End Sub
'交换两个数的位置
Public Sub Swap(ByRef a, ByRef b)
Dim temp
temp = a: a = b: b = temp
End Sub
请指点,为何我写了vb无法正常运行