菜鸟自己做的VB程序,不知道错在哪里了?
Public a As IntegerPublic b As Integer
Public c As Integer
Public d As Integer
Public e As Integer
Public f As Integer
Function GetLen(m As Variant, n As Variant) As Integer
If m = 0 And n = 1 Then
GetLen = a
ElseIf m = 0 And n = 2 Then
GetLen = b
ElseIf m = 0 And n = 3 Then
GetLen = c
ElseIf m = 1 And n = 0 Then
GetLen = a
ElseIf m = 2 And n = 0 Then
GetLen = b
ElseIf m = 3 And n = 0 Then
GetLen = c
ElseIf (m * 10 + n) = 12 Or (m * 10 + n) = 21 Then
GetLen = d
ElseIf (m * 10 + n) = 13 Or (m * 10 + n) = 31 Then
GetLen = e
ElseIf (m * 10 + n) = 23 Or (m * 10 + n) = 32 Then
GetLen = f
Else
GetLen = -1000
End If
End Function
Function LnLen(Arr(), i As Integer) As Integer
Dim j As Integer
LnLen = 0
For j = 0 To i - 2
LnLen = LnLen + GetLen(Arr(j), Arr(j + 1))
Next j
End Function
Private Sub Command1_Click()
a = Val(Text1.Text): b = Val(Text2.Text): c = Val(Text3.Text): d = Val(Text4.Text): e = Val(Text5.Text): f = Val(Text6.Text)
If a <= 0 Or b <= 0 Or c <= 0 Or d <= 0 Or e <= 0 Or f <= 0 Then MsgBox "距离输入有误!", vbOKOnly + vbCritical, "提示"
Dim M1()
Dim M2()
Dim M3()
Dim M4()
Dim M5()
Dim M6()
Dim N1()
Dim N11()
Dim N12()
Dim N2()
Dim N21()
Dim N22()
Dim N3()
Dim N31()
Dim N32()
Dim O1()
Dim O2()
Dim O3()
Dim cmp(1 To 13) As Integer, i As Integer, j As Integer, k As Integer
M1 = Array(0, 1, 2, 3, 0): M2 = Array(0, 1, 3, 2, 0): M3 = Array(0, 2, 1, 3, 0): M4 = Array(0, 2, 3, 1, 0): M5 = Array(0, 3, 1, 2, 0): M6 = Array(0, 3, 2, 1, 0)
N1 = Array(0, 1, 0): N11 = Array(0, 2, 3, 0): N12 = Array(0, 3, 2, 0)
N2 = Array(0, 2, 0): N21 = Array(0, 1, 3, 0): N22 = Array(0, 3, 1, 0)
N3 = Array(0, 3, 0): N21 = Array(0, 1, 2, 0): N22 = Array(0, 2, 1, 0)
O1 = Array(0, 1, 0): O2 = Array(0, 2, 0): O3 = Array(0, 3, 0)
Text7.Text = "0,1,2,3,0": Text8.Text = LnLen(M1, 5): cmp(1) = LnLen(M1, 5)
Text9.Text = "0,1,3,2,0": Text10.Text = LnLen(M2, 5): cmp(2) = LnLen(M2, 5)
Text11.Text = "0,2,1,3,0": Text12.Text = LnLen(M3, 5): cmp(3) = LnLen(M3, 5)
Text13.Text = "0,2,3,1,0": Text14.Text = LnLen(M4, 5): cmp(4) = LnLen(M4, 5)
Text15.Text = "0,3,1,2,0": Text16.Text = LnLen(M5, 5): cmp(5) = LnLen(M5, 5)
Text17.Text = "0,3,2,1,0": Text18.Text = LnLen(M6, 5): cmp(6) = LnLen(M6, 5)
Text19.Text = "0,1,0,0,2,3,0": Text20.Text = LnLen(N1, 3) + LnLen(N11, 4): cmp(7) = LnLen(N1, 3) + LnLen(N11, 4)
Text21.Text = "0,1,0,0,3,2,0": Text22.Text = LnLen(N1, 3) + LnLen(N12, 4): cmp(8) = LnLen(N1, 3) + LnLen(N12, 4)
Text23.Text = "0,2,0,0,1,3,0": Text24.Text = LnLen(N2, 3) + LnLen(N21, 4): cmp(9) = LnLen(N2, 3) + LnLen(N21, 4)
Text25.Text = "0,2,0,0,3,1,0": Text26.Text = LnLen(N2, 3) + LnLen(N22, 4): cmp(10) = LnLen(N2, 3) + LnLen(N22, 4)
Text27.Text = "0,3,0,0,1,2,0": Text28.Text = LnLen(N3, 3) + LnLen(N31, 4): cmp(11) = LnLen(N3, 3) + LnLen(N31, 4)
Text29.Text = "0,3,0,0,2,1,0": Text30.Text = LnLen(N3, 3) + LnLen(N32, 4): cmp(12) = LnLen(N3, 3) + LnLen(N32, 4)
Text31.Text = "0,1,0,0,2,0,0,3,0": Text32.Text = LnLen(O1, 3) + LnLen(O2, 3) + LnLen(O3, 3): cmp(13) = LnLen(O1, 3) + LnLen(O2, 3) + LnLen(O3, 3)
j = 13: k = cmp(13)
For i = 12 To 1 Step -1
If cmp(i) < k Then k = cmp(i): j = i
Next i
Text33.Text = j
End Sub
Private Sub Command2_Click()
Text1.Text = "1": Text2.Text = "1": Text3.Text = "1": Text4.Text = "1": Text5.Text = "1": Text6.Text = "1"
Text7.Text = "": Text8.Text = "": Text9.Text = "": Text10.Text = "": Text11.Text = "": Text12.Text = "": Text13.Text = ""
Text14.Text = "": Text15.Text = "": Text16.Text = "": Text17.Text = "": Text18.Text = "": Text19.Text = "": Text20.Text = ""
Text21.Text = "": Text22.Text = "": Text23.Text = "": Text24.Text = "": Text25.Text = "": Text26.Text = "": Text27.Text = ""
Text28.Text = "": Text29.Text = "": Text30.Text = "": Text31.Text = "": Text32.Text = "": Text33.Text = ""
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Timer1_Timer()
Text34.Text = Now
End Sub
小弟的问题是红色部分编译出错说,数组下标越界(LnLen = LnLen + GetLen(Arr(j), Arr(j + 1))),下面这句Function LnLen(Arr(), i As Integer) As Integer,i是Arr数组元素的个数,怎么会错,我不知道是什么意思。另外不知道数组怎么做一个function的参数,有什么要注意的,我用的是VB6.0。请高手指教,谢谢。
[ 本帖最后由 qq1023569223 于 2010-12-22 15:06 编辑 ]