这是由数控系统界面根据用户的输入而生成的一个文件(或者说是“中间”的文件,因为这个文件还需要被编译成NC程序),我们想在原有基础上进行硬件的改动(当然,运行库函数等都需要重新修改),但对用户来说,从表面上看应该和以前没有区别,所以,我们也保留了程序转换方面的部分。可惜的是我对文件的读取方面不是很懂- -!原本这就不是我的程序。
问题是:
    VB里对文本文件的读取。如何寻找下一行。如何提取某行中的某部分,比如:
第八行 11   test Axis B Degree 91.22 
如何找到AXIS 后面的B ,以及 DEGREE 后面的91。22
- -!狂汗。。
因为这个项目有时间没接触了,而且,我的VB也不是很好,大家不要笑话我。
(- -||)最近,喜欢的一个网吧MM有日子没见到了,心情烦躁,天生胆小,还没来得及表白呢18 test
8 test
13 test M 41
13 test M 43
13 test M 45
2 test No 2 S 4600
12 test
11 test Axis B Degree 91.22
1 test Axis C Degree 152.65
1 test Axis W Degree 18.2
12 test
5 test Z1 35.41 Z2 .8 F .13 W 0
11 test Axis B Degree 89.58
1 test Axis C Degree 72.93
1 test Axis W Degree 18.2
12 test
5 test Z1 35.41 Z2 .8 F .13 W 0
11 test Axis B Degree 66.43
1 test Axis C Degree 9.1
1 test Axis W Degree 18.45
12 test
5 test Z1 35.41 Z2 .8 F .13 W 0
11 test Axis B Degree 65.05
1 test Axis C Degree 226.33
1 test Axis W Degree 18.45
12 test
5 test Z1 35.41 Z2 .8 F .13 W 0
11 test Axis B Degree 52.57
1 test Axis C Degree 300.6
1 test Axis W Degree 18.63
12 test
5 test Z1 35.41 Z2 .8 F .13 W 0
2 test No 3 S 4600
12 test
5 test Z1 34.69 Z2 2 F .2 W 0
11 test Axis B Degree 65.05
1 test Axis C Degree 226.33
1 test Axis W Degree 18.45
12 test
5 test Z1 34.69 Z2 2 F .2 W 0
11 test Axis B Degree 66.43
1 test Axis C Degree 9.1
1 test Axis W Degree 18.45
12 test
5 test Z1 34.69 Z2 2 F .2 W 0
11 test Axis B Degree 89.58
1 test Axis C Degree 72.93
1 test Axis W Degree 18.2
12 test
5 test Z1 34.69 Z2 2 F .2 W 0
11 test Axis B Degree 91.22
1 test Axis C Degree 152.65
1 test Axis W Degree 18.2
12 test
5 test Z1 34.69 Z2 2 F .2 W 0
2 test No 1 S 4600
12 test
5 test Z1 34.69 Z2 2.1 F .4 W 0
11 test Axis B Degree 89.58
1 test Axis C Degree 72.93
1 test Axis W Degree 18.2
12 test
5 test Z1 34.69 Z2 2.1 F .4 W 0
11 test Axis B Degree 66.43
1 test Axis C Degree 9.1
1 test Axis W Degree 18.45
12 test
5 test Z1 34.69 Z2 2.1 F .4 W 0
11 test Axis B Degree 65.05
1 test Axis C Degree 226.33
1 test Axis W Degree 18.45
12 test
5 test Z1 34.69 Z2 2.1 F .4 W 0
11 test Axis B Degree 52.57
1 test Axis C Degree 300.6
1 test Axis W Degree 18.63
12 test
5 test Z1 34.69 Z2 2.1 F .4 W 0
4 test
13 test M 44
13 test M 42
20 test

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/3958/3958132.xml?temp=.7802851'整个文件读到一个字符串
    dim strALL as string
    Open "c:\tet.txt" For Input As 1
    strALL = Strconv(InputB$(LOF(1), 1), vbUnicode)'按行分割到数组
    dim astr() as string
    astr=split(str1.vbCrLf)'第八行
    dim str1 as string,str2 as string,str3 as string
    str1 = astr(7)
    if instr(str1,"AXIS")>0 then
       str2=mid(str1,instr(str1,"AXIS")+5,1)'取出"B"
    end if
    if instr(str1,"DEGREE")>0 then
       str3=mid(str1,instr(str1,"DEGREE")+7,5)'取出"91.22"
    end if
      

  2.   

    '整个文件读到一个字符串
    dim strALL as string
    Open "c:\tet.txt" For Input As 1
    strALL = Strconv(InputB$(LOF(1), 1), vbUnicode)'按行分割到数组
    dim astr() as string
    astr=split(strALL.vbCrLf)'第八行
    dim str1 as string,str2 as string,str3 as string
    str1 = astr(7)
    if instr(str1,"AXIS")>0 then
       str2=mid(str1,instr(str1,"AXIS")+5,1)'取出"B"
    end if
    if instr(str1,"DEGREE")>0 then
       str3=mid(str1,instr(str1,"DEGREE")+7,5)'取出"91.22"
    end if
      

  3.   

    "91.22"的长度可用 行总长度-len("DEGREE")-2
      

  4.   

    "91.22"的长度可用 行总长度-instr(str1,"DEGREE")-len("DEGREE")+1