VB实现最短路径问题,代码哪里不对

本来是通过组合框输入起始站,现在直接换成常数后提示下标越界,大家给看看为什么?
Private Sub CommandSearch_Click()
Dim iCurrename As Integer
Dim iEndName As Integer
Dim iStartName As Integer
Dim sPathList As String

 '开始搜索
If Me.ComboStart.ListIndex = 0 Or Me.ComboEnd.ListIndex = 0 Then
    MsgBox "请选择“起点站”或“终点站”!"
    Exit Sub
End If
iEndName = Me.ComboEnd.ListIndex
iCurrename = iEndName
iStartName = Me.ComboStart.ListIndex
sPathList = ""

Call SearchPath(Me.ComboStart.ListIndex, Me.ComboEnd.ListIndex)


'显示结果
Do While iCurrename <> iStartName
    If (iPath(iCurrename) = 0) Then
        Me.TextResult.Text = "没有路: " & sAddList(iStartName) & " 到" & sAddList(iEndName) & "!" & vbCrLf
        Exit Sub
    End If
    sPathList = sAddList(iCurrename) & sPathList
    GetResult (iCurrename)
    sPathList = " -> " & sPathList
    iCurrename = iPath(iCurrename)
Loop
sPathList = sAddList(iStartName) & sPathList
GetResult (iStartName)
' /* 打印显示距离 */
sPathList = "距离是: " & iPathLength(iEndName) & vbCrLf & sPathList

Me.TextResult.Text = sPathList

End Sub
Public Function SearchPath(iStartName As Integer, iEndName As Integer)
'iStartName '开始点
'iEndName '结束点

Dim iCurrename As Integer
Dim iTotalLength As Integer

Dim bCanSearch As Boolean


iCurrename = iStartName
'MsgBox iCurrename
iTotalLength = 0             '设定开始距离
bCanSearch = True

Dim min As Long


'//下面的代码初始化其他数组
For iLoop = 1 To iAddCount
    '初始化选择点:1表示没有选中,0表示被选中
    iAddSelect(iLoop) = "False"
    iPathLength(iLoop) = NoPath
    iPath(iLoop) = 0
Next

'从图上显示当前第一个节点被搜索
iAddSelect(iCurrename) = "True"
iPathLength(iCurrename) = 0
iResultSize = 0
 Do While bCanSearch
    '/* 更改数组中的距离 */
    For iLoop = 1 To iAddCount
        If ((iAddMap(iCurrename, iLoop) <> 0) And _
             ((iPathLength(iLoop)) > (iAddMap(iCurrename, iLoop)) + iTotalLength)) Then
            iPathLength(iLoop) = iAddMap(iCurrename, iLoop) + iTotalLength
            iPath(iLoop) = iCurrename
        End If
    Next iLoop


    min = NoPath

    For iLoop = 1 To iAddCount
        If ((iPathLength(iLoop) < min) And (iAddSelect(iLoop) = "False")) Then
            min = iPathLength(iLoop)
            iCurrename = iLoop
            iTotalLength = iPathLength(iLoop)
        End If
    Next iLoop
    iAddSelect(iCurrename) = "True"

    '/* 处理完成所有的顶点之后停止 */
    If (min = NoPath) Then
        bCanSearch = False
    End If
    '测试代码
    DoEvents
Loop

End Function

vb

1个回答

数组定义在哪呢,哪越界呢。
参考
http://blog.sina.com.cn/s/blog_4940204c010002q7.html

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐