求助文件处理
我有一个txt文件格式如下:53478 20131231000000 400000 1122700 -8.1
53486 20131231000000 402200 1134600 -4.9
...
其中第3列是经度,第四列是维度,然后我想把经纬度作为一个数组的下标,怎么从这个txt文件中截取啊?
Option Explicit Option Base 1 Dim array_xy(100) As String '这里暂定有100行需要读取的信息,具体情况自己设置 Private Function search(ByVal x As String, ByVal y As String) As String '定义个搜索函数 Dim jingdu As String, weidu As String, infor As String, n As Integer, pos As Integer, last As Integer Dim count As Integer Open "文件的路径" For Input As #1 Do While Not EOF(1) pos = 1 count = count + 1 Line Input #1, array_xy(count) For n = 1 To 4 pos = InStr(pos, array_xy(count), Space(4)) '看了一下你的每个数据隔了4个空格,如果不是4个,你自己再改一下 If n = 2 Then last = pos If n = 3 Then jingdu = Trim(Mid(array_xy(count), last, pos - last)): last = pos '读取纬度 If n = 4 Then weidu = Trim(Mid(array_xy(count), last, pos - last)) '读取经度 infor = Trim(Right(array_xy(count)), Len(array_xy(count) - pos)) '读取第5列信息 End If Next n If x = jingdu And y = weidu Then search = infor: Exit Function Loop MsgBox "没有搜索到相关的信息", vbOKOnly, "提示" search = vbNullString Close #1 End Function Private Sub Command1_Click() Dim result As String result = search(经度,纬度) End Sub