就是让你读一行,处理一行的********************* Public Sub red_station() Dim i, j, n As Integer Dim a() As String, b() As String, c() As Single, d() As Single,e() As Single dim strTemp as stringfile_name = "d:\1.txt" Open file_name For Input As #1 Input #1, n '读入第一行(10个站点) ReDim a(n-1) As String, b(n-1) As String, c(n-1) As Single,d(n-1) As Single,e(n-1) As Single For i = 0 To n - 1 Input #1, strtempDo While InStr(strtemp, " ") > 0 '直到没有两个空格 strtemp = Replace(strtemp, " ", " ") '把两个空格替换成1个空格 Loop Input #1, a(i), b(i),c(i),d(i),e(i) Next Close #1 End Sub
就是让你读一行,处理一行的********************* Public Sub red_station() Dim i, j, n As Integer Dim a() As String, b() As String, c() As Single, d() As Single,e() As Single dim strTemp as string dim t() as stringfile_name = "d:\1.txt" Open file_name For Input As #1 Input #1, n '读入第一行(10个站点) ReDim a(n-1) As String, b(n-1) As String, c(n-1) As Single,d(n-1) As Single,e(n-1) As SingleFor i = 0 To n - 1 Input #1, strtemp Do While InStr(strtemp, " ") > 0 '直到没有两个空格 strtemp = Replace(strtemp, " ", " ") '把两个空格替换成1个空格 Loop
t=split(strtemp," ") redim preserve t(4) a(i)=t(0) b(i)=t(1) c(i)=t(2) d(i)=t(3) e(i)=t(4) Next Close #1 End Sub
Input #1, strtempDo While InStr(strtemp, " ") > 0
strtemp = Replace(strtemp, " ", " ")
Loop
之前我也遇到这种情况,我的处理办法是先导入excel中再从excel中读取,现在看来太麻烦了
晕,csdn把空格吞了
Input #1, strtempDo While InStr(strtemp, " ") > 0 '直到没有两个空格
strtemp = Replace(strtemp, " ", " ") '把两个空格替换成1个空格
Loop
Public Sub red_station()
Dim i, j, n As Integer
Dim a() As String, b() As String, c() As Single, d() As Single,e() As Single
dim strTemp as stringfile_name = "d:\1.txt"
Open file_name For Input As #1
Input #1, n '读入第一行(10个站点)
ReDim a(n-1) As String, b(n-1) As String, c(n-1) As Single,d(n-1) As Single,e(n-1) As Single
For i = 0 To n - 1
Input #1, strtempDo While InStr(strtemp, " ") > 0 '直到没有两个空格
strtemp = Replace(strtemp, " ", " ") '把两个空格替换成1个空格
Loop
Input #1, a(i), b(i),c(i),d(i),e(i)
Next
Close #1
End Sub
Public Sub red_station()
Dim i, j, n As Integer
Dim a() As String, b() As String, c() As Single, d() As Single,e() As Single
dim strTemp as string
dim t() as stringfile_name = "d:\1.txt"
Open file_name For Input As #1
Input #1, n '读入第一行(10个站点)
ReDim a(n-1) As String, b(n-1) As String, c(n-1) As Single,d(n-1) As Single,e(n-1) As SingleFor i = 0 To n - 1
Input #1, strtemp Do While InStr(strtemp, " ") > 0 '直到没有两个空格
strtemp = Replace(strtemp, " ", " ") '把两个空格替换成1个空格
Loop
t=split(strtemp," ")
redim preserve t(4)
a(i)=t(0)
b(i)=t(1)
c(i)=t(2)
d(i)=t(3)
e(i)=t(4)
Next
Close #1
End Sub