| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 389 人关注过本帖, 1 人收藏
标题:看到一个程序不知道它读取文本文件中的值如何处理,求大侠指点迷津
只看楼主 加入收藏
ych9631
Rank: 1
等 级:新手上路
帖 子:4
专家分:5
注 册:2012-12-2
结帖率:100%
收藏(1)
已结贴  问题点数:20 回复次数:3 
看到一个程序不知道它读取文本文件中的值如何处理,求大侠指点迷津
Option Explicit
Dim start, ends As Long
Dim JLH(1 To 300), LJD(1 To 300, 1 To 4), DST(1 To 300, 1 To 4) As Long
Dim BH(1 To 300), ADD(1 To 300) As String
Dim n As Integer
Dim vertexnum As Integer
Dim edgenum As Integer
Const max = 100000
Dim graph(0 To 300, 0 To 300) As Long
Dim visited(0 To 300) As Integer
Dim path(0 To 300) As Integer
Dim distance(0 To 90000) As Long

Private Function dijkstra(begin As Integer)
    Dim minedge, vertex, i, j, n, m, edges As Integer
    edges = 1
    visited(begin) = 1
    For i = 1 To vertexnum
        distance(i) = graph(begin, i)
        'Print distance(i)
    Next i
   
        distance(begin) = 0
              While (edges < vertexnum - 1)
                edges = edges + 1
                minedge = max
                For j = 1 To vertexnum
                    If visited(j) = 0 And minedge > distance(j) Then
                        vertex = j
                        minedge = distance(j)
                    End If
                Next j
                visited(vertex) = 1
                For n = 1 To vertexnum
                    If visited(n) = 0 And (distance(vertex) + graph(vertex, n)) < distance(n) Then
                        distance(n) = distance(vertex) + graph(vertex, n)
                        path(n) = vertex
                    End If
                Next
              Wend
End Function
Private Sub Command1_Click()
    Dim i, j As Integer
    Dim k As Integer
    Dim addname(1 To 100) As String
   
    Text1 = ""
        If start = 0 Or ends = 0 Then
        MsgBox "请选择起始站与终点站"
        Exit Sub
    End If
    For i = 1 To vertexnum
        visited(i) = 0
        path(i) = 1
    Next
    dijkstra (start)
    Text1 = "起讫站:" & ADD(start) & "  -->  " & "终点站:" & ADD(ends) & vbCrLf
    Text1 = Text1 & vbCrLf
    If distance(ends) = max Then
        Text1 = Text1 & "两站点间没有可联接的路线!"
        Exit Sub
    Else
        Text1 = Text1 & "它们之间的距离为: " & distance(ends) * 0.1 & "  Km" & vbCrLf
        Text1 = Text1 & vbCrLf
        Text1 = Text1 & "它们之间的最短路线为:" & vbCrLf
        Text1 = Text1 & vbCrLf
        Text1 = Text1 & ADD(start)
    End If
    k = ends
    j = 1
    Do
        addname(j) = ADD(k)
        k = path(k)
        j = j + 1
    Loop While (k <> 1)
    For j = j - 1 To 1 Step -1
        Text1 = Text1 & "--> " & addname(j)
    Next j
End Sub

Private Sub Form_Initialize()
    Dim i, j, k As Long
    Dim filename As String
    Dim buffers As String
   
    On Error Resume Next
   
    filename = App.path + "\" + "Add_Dst" + ".txt"
    Open filename For Input As #1
    If LOF(1) = 0 Then
        MsgBox "The lenth of the file is zero! Please Select it asgain。" & vbCrLf & "The file name is Add_Dst。"
        
        Exit Sub
    End If
    i = 1
   
   
    Do While Not EOF(1)
    Line Input #1, buffers
        BH(i) = Val(Mid$(buffers, 1, 3))
   
        ADD(i) = Mid$(buffers, 4, 4)
            
            Combo1.AddItem ADD(i)
           Combo2.AddItem ADD(i)
        LJD(i, 1) = Val(Mid$(buffers, 8, 3))    '邻接点的编号
      
        DST(i, 1) = Val(Mid$(buffers, 11, 2))    '与邻接点之间的距离
        LJD(i, 2) = Val(Mid$(buffers, 13, 3))
        DST(i, 2) = Val(Mid$(buffers, 16, 2))
        LJD(i, 3) = Val(Mid$(buffers, 18, 3))
        DST(i, 3) = Val(Mid$(buffers, 21, 2))
        LJD(i, 4) = Val(Mid$(buffers, 24, 3))
        DST(i, 4) = Val(Mid$(buffers, 27, 2))
       Kill buffers
        i = i + 1
    Loop
        n = i - 1
'Debug.Print n
'Print LJD(i, 1)
Close #1
      
    vertexnum = n  '设置图的顶点数
   
    edgenum = 0
   
    For i = 1 To n
        For j = 1 To 4
            If LJD(i, j) = 0 Then Exit For
            edgenum = edgenum + 1    '获得图的边数
            graph(i, LJD(i, j)) = DST(i, j)   '从i点与其邻接点LJD(i,j)的距离
        Next
    Next

    For i = 0 To n
        For j = 0 To n
            If graph(i, j) = 0 Then
                graph(i, j) = max
            End If
        Next
    Next
End Sub
Private Sub Combo1_click()
    start = Combo1.ListIndex + 1      '获得起讫站的编号
End Sub

Private Sub Combo2_click()
    ends = Combo2.ListIndex + 1      '获得终点站的编号
End Sub

搜索更多相关主题的帖子: max distance 文本文件 start 
2012-12-02 20:26
ych9631
Rank: 1
等 级:新手上路
帖 子:4
专家分:5
注 册:2012-12-2
收藏
得分:0 
001安  定1450424908
002八坼站 007041600420406
003八  城114030540409203
004八  都1350922604
005摆渡口 0420303805
006百  花15103
007白龙桥 2150700204
008白  茆201042820809505
009板  桥0360319204
010宝  岩0190602804
011北  库0670608406
012北  桥26203
013碧  溪217082130428405
014兵  希2430513305
015曹安路 07005

文本文件如上所述。不知道后面的数字有何作用
2012-12-02 20:27
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
收藏
得分:14 
路线规划
文本文件后面的数字记录连接点及距离

无知
2012-12-03 12:51
ych9631
Rank: 1
等 级:新手上路
帖 子:4
专家分:5
注 册:2012-12-2
收藏
得分:0 
回复 3楼 Artless
那请问怎么同时表示连接点和距离的呢?
2012-12-03 17:15
快速回复:看到一个程序不知道它读取文本文件中的值如何处理,求大侠指点迷津
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033054 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved