xmok 发表于 2008-10-31 21:54:00

[求助]VB读取数据文件的求助

<p>1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=-6.6660&nbsp;&nbsp;&nbsp; Y=-9.0000&nbsp;&nbsp;&nbsp; Z=7.5926&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=-5.0010&nbsp;&nbsp;&nbsp; Y=-10.6386&nbsp;&nbsp; Z=9.2911&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=-8.3340&nbsp;&nbsp;&nbsp; Y=-10.6386&nbsp;&nbsp; Z=9.2911&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=-13.3320&nbsp;&nbsp; Y=-9.0000&nbsp;&nbsp;&nbsp; Z=7.5926&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=-11.6670&nbsp;&nbsp; Y=-10.6386&nbsp;&nbsp; Z=9.2911&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=-15.0000&nbsp;&nbsp; Y=-10.6386&nbsp;&nbsp; Z=9.2911&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=-19.9980&nbsp;&nbsp; Y=-9.0000&nbsp;&nbsp;&nbsp; Z=7.5926&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=-18.3330&nbsp;&nbsp; Y=-10.6386&nbsp;&nbsp; Z=9.2911&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 9&nb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nbsp; <br/>&nbsp;&nbsp; 18&nbsp;&nbsp;&nbsp;&nbsp; X=-11.6670&nbsp;&nbsp; Y=-7.6322&nbsp;&nbsp;&nbsp; Z=9.8935&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 19&nbsp;&nbsp;&nbsp;&nbsp; X=-15.0000&nbsp;&nbsp; Y=-7.6322&nbsp;&nbsp;&nbsp; Z=9.8935&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; 20&nbsp;&nbsp;&nbsp;&nbsp; X=-18.3330&nbsp;&nbsp; Y=-7.6322&nbsp;&nbsp;&nbsp; Z=9.8935&nbsp;&nbsp;&nbsp;&nbsp; </p><p>我想得到每一行等号之后的数据,有没有好的办法快速得到?</p><p>在这里先谢谢各位大侠了。</p><p></p>

王咣生 发表于 2008-11-1 14:25:00

用两次Split函数,第一次以空格分割,第二次以"="分割.<br/>例如:<br/><br/>Sub test()<br/>    Dim s As String<br/>    s = "20     X=-18.3330   Y=-7.6322    Z=9.8935"<br/><br/>    Dim v As Variant<br/>    v = VBA.Split(s, " ")<br/>    <br/>    Dim col As New Collection<br/>    Dim i As Integer<br/>    For i = LBound(v) To UBound(v)<br/>        If VBA.InStr(1, v(i), "=") &gt; 0 Then<br/>            Dim vv As Variant<br/>            vv = VBA.Split(v(i), "=")<br/>            col.Add vv(1)<br/>        End If<br/>    Next<br/>    <br/>    '显示结果<br/>    For i = 1 To col.Count<br/>        MsgBox col(i)<br/>    Next<br/>End Sub<br/>

兰州人 发表于 2008-11-1 18:32:00

<p>这是字符分离问题.</p><p>要点Split(s, " ")关键语句.<br/></p>

mccad 发表于 2008-11-1 20:17:00

我的方法是先把X=,Y=和Z=删除掉,再Split,得到的数组就可以直接用了。

AirCD 发表于 2008-11-10 21:30:00

请问明总,以上你所说的方法如何实现呢?怎样删除这些数据?请指教

mccad 发表于 2008-11-10 21:49:00

这还不简单:v=Split(Replace(Replace(Replace(s,"X=",""),"Y=",""),"Z=","")," ")

robbin840311 发表于 2008-11-11 08:01:00

<p>如明总所说,写程序就要找出最简单的规律。如果一定要使用程序替换的话,明总的办法最好;如果不使用程序替换,直接在记事本中打开,然后替换。</p>

AirCD 发表于 2008-11-11 10:16:00

恩,学习了,谢谢两位.

zqbxfev 发表于 2008-11-21 12:25:00

<p>学习到一点啊,确实比较方便!</p><p>顶一下!谢谢了!</p>

xmok 发表于 2008-11-29 09:19:00

谢谢了。
页: [1]
查看完整版本: [求助]VB读取数据文件的求助