文本内容如下:
(2 18.13 15.0) 114111 38159 Pin Extra
(2 18.09 16.0) 12611 3791 Abbcc Extra
(2 18.00 50.0) 1611 37275 Pin Extra
(2 18.11 51.0) 111 38078 Pind Extra
等等
我怎么读取里面的数据啊,有3个函数x(),y(),t()
想实现这样效果:x(1)=114111 x(2)=12611,x(3)=1611 等等
y(1)=38159 y(2)=3791 等等
t(1)="pin" t(2)="Abbcc" 等等
应该怎么编程??
大致程序如下,请高手帮我修改完成:
Dim inserts_x() as string
Dim inserts_y() as string
Dim inserts_t() as string
dim i as integer
Open CurDir & "\inserts" For Input As #2
Do While Not EOF(1)
Line Input #2, tempStr001
If Mid(tempStr001, 6, 1) = "." And Mid(tempStr001, 13, 1)= "." Then
ReDim Preserve inserts_x(i)
ReDim Preserve inserts_y(i)
ReDim Preserve inserts_t(i)
'用类似这样的函数
'Mid(tempStr001,1,InStr(1, tempStr, "Y"))
drill_x(i) = 什么什么1
drill_y(i) = 什么什么2
drill_t(i) = 什么什么3
End If
Loop
Close #2
參考答案:帮你弄出来了. 希望你喜欢哦~~ 我测试时数据放在 c:\1.txt 不是的话自己改一下.
结果存放在 result_x, result_y, result_z三个数组了. 最后一行我加入了stop语句, 你调试时程序会停下来, 你可以对这三个数组添加监视看看结果对不对. 有什么EMAIL我~~
Private Sub Command1_Click()
Dim s() As String
Dim curStr As String
Dim totalLines As Long
Open "c:\1.txt" For Input As #3
While Not EOF(3)
Line Input #3, curStr
If Len(curStr) > 0 Then
curStr = Trim(Right(curStr, Len(curStr) - InStr(1, curStr, ")", vbTextCompare)))
totalLines = totalLines + 1
ReDim Preserve s(totalLines)
s(totalLines) = curStr
End If
Wend
Close #3
Dim i As Long
Dim curAry() As String
Dim result_x() As String
Dim result_y() As String
Dim result_z() As String
ReDim result_x(totalLines)
ReDim result_y(totalLines)
ReDim result_z(totalLines)
For i = 1 To totalLines
curAry = Split(s(i), " ", , vbTextCompare)
result_x(i) = curAry(0)
result_y(i) = curAry(1)
result_z(i) = curAry(2)
Next
'得到结果了. 将STOP语句改为您想要的语句即可
Stop
End Sub