求助啊,,例如如图片所示,已有各个车次停站信息,我需要得到每两个停靠站点之间经过的列车数,
结果显示如:
          北京南  德州东 济南 上海 ...........
北京南              
德州东
济南
上海

解决方案 »

  1.   

    这个容易啊。首先,得到两个站经过的列车的列表,然后,查找这两个站共有的列车。假定你的信息是保存在数据库中的。代码中借助了 3 个 ListBox,它们可以设置成不可见的。'在列表框中查找相同字符串的 API
    Private Declare Function SendMessagebyString Lib _
    "user32" Alias "SendMessageA" (ByVal hWND As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
    ByVal lParam As String) As LongPrivate Const LB_FINDSTRINGEXACT = &H1A2    '在 ListBox 中精确查找'获取所有站名
    Set rs = cn.Execute("SELECT DISTINCT stop_name FROM your_table ORDER BY stop_name") 
    List1.Clear
    Do Until rs.EOF
        List1.AddItem rs!stop_name
        rs.MoveNext
    Loop'遍历所有的车站对
    For i = 0 To List1.ListCount - 2
        '获取此站的列车
        Set rs = cn.Execute("SELECT train_number FROM your_table WHERE stop_name ='" & List1.List(i) & "'") 
         List2.Clear
        Do Until rs.EOF
            List2.AddItem rs!train_number
            rs.MoveNext
        Loop
        For j = i + 1 To List1.ListCount - 1
            '获取彼站的列车
            Set rs = cn.Execute("SELECT train_number FROM your_table WHERE stop_name ='" & List1.List(j) & "'")   
            List3.Clear
            Do Until rs.EOF
                If SendMessagebyString(List2.hWnd, LB_FINDSTRINGEXACT, -1, rs!train_number) > -1 Then List3.AddItem rs!train_number
                rs.MoveNext
            Loop
            Debug.Print List1.List(i) & "<->" & List1.List(j)
            If List3.ListCount = 0 Then
                Debug.Print "没有直通列车"
            Else
                For k = 0 To List3.ListCount -1
                    Debug.Print List3.List(k)
                Next k
            End If
        Next j
    Next i