| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1918 人关注过本帖, 1 人收藏
标题:vb 将计算出的数据添加到txt文件中
只看楼主 加入收藏
xyzmrsir
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-4-15
结帖率:0
收藏(1)
已结贴  问题点数:20 回复次数:3 
vb 将计算出的数据添加到txt文件中
Private Sub Form_Click()
Dim reg As New RegExp
reg.Pattern = "[\d\.]+"
reg.Global = True: reg.IgnoreCase = True: reg.MultiLine = True
Dim textline As String
Dim temp() As String  '第n行的x和y
Dim temp1() As String  '第n+1行的x和y
Dim temp2() As String  '第n行的时间
Dim temp3() As String  '第n+1行的时间
Dim distance() As String
Dim timeInterval() As String
Dim speed() As String
Open "e:\data.txt" For Input As #1

ReDim temp(1)
ReDim temp1(0)
ReDim temp2(2)
ReDim temp3(0)
ReDim distance(0)
ReDim timeInterval(0)
ReDim speed(0)
Do While Not EOF(1)
Line Input #1, textline
temp(0) = reg.Execute(textline)(3)    'x
temp(1) = reg.Execute(textline)(4)    'y

If (UBound(temp1) >= 1) Then

distance(0) = (temp(0) - temp1(0)) ^ 2 + (temp(1) - temp1(1)) ^ 2

Print textline, distance(0)
End If
ReDim temp1(1)
temp1(0) = reg.Execute(textline)(3)
temp1(1) = reg.Execute(textline)(4)
Loop
Close #1
End Sub

Private Sub Form_Load()

End Sub

计算结果如下:
图片附件: 游客没有浏览图片的权限,请 登录注册


在要保留原数据(前三列)的情况下,怎么把计算出来的结果distance(最后一列是计算结果distance) ,写入txt的最后一列???????

txt中原数据如下:
14:04:16     31.0042     121.19409
14:04:57     31.004078     121.191348
14:05:08     31.00401     121.190088
14:05:25     31.0039     121.187448
14:05:28     31.003878     121.18694
14:05:39     31.00384     121.18541

最终想要的txt中的数据格式是:
14:04:16     31.0042     121.19409    7.53344799998821E-06(手工录入最后一列,哭)
14:04:57     31.004078     121.191348    1.59222400000498E-06(手工录入最后一列,哭)
14:05:08     31.00401     121.190088    6.98169999999739E-06(手工录入最后一列,哭)
14:05:25     31.0039     121.187448    2.5854799999964E-06(手工录入最后一列,哭)
14:05:28     31.003878     121.18694    2.34234400000757E-06(手工录入最后一列,哭)
14:05:39     31.00384     121.18541   

在要保留原数据(前三列)的情况下,怎么把计算出来的结果distance(最后一列是计算结果distance) ,写入txt的最后一列???????
搜索更多相关主题的帖子: distance speed 
2016-04-15 11:29
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4941
专家分:30047
注 册:2008-10-15
收藏
得分:7 
Open "e:\data.txt" For Input As #1
Open "e:\tmp.txt" For output As #2
ReDim temp(1)
ReDim temp1(0)
ReDim temp2(2)
ReDim temp3(0)
ReDim distance(0)
ReDim timeInterval(0)
ReDim speed(0)
Do While Not EOF(1)
Line Input #1, textline
temp(0) = reg.Execute(textline)(3)    'x
temp(1) = reg.Execute(textline)(4)    'y

If (UBound(temp1) >= 1) Then

distance(0) = (temp(0) - temp1(0)) ^ 2 + (temp(1) - temp1(1)) ^ 2

Print textline, distance(0)
Print #2,textline, distance(0)
End If
ReDim temp1(1)
temp1(0) = reg.Execute(textline)(3)
temp1(1) = reg.Execute(textline)(4)
Loop
Close #1
Close #2

未经测试,你自己试试。

授人于鱼,不如授人于渔
早已停用QQ了
2016-04-15 17:39
xiangyue0510
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:86
帖 子:938
专家分:5244
注 册:2015-8-10
收藏
得分:7 
楼上说的确实是实情,一方面现在网络比较发达,很多的问题可以找到答案。来问的人可能就不多了
另外一方面也是有些会员实在过分,很简单的问题不去开动脑筋,思路都告诉了,就是说不会,只会伸手。 搞的别人不愿意去帮。
但是想楼主这样的,确实自己写了代码,调试不出来的,我们都是还是愿意帮忙的。毕竟谁都有刚开始学习懵懵懂懂的那个阶段。
2016-04-16 13:22
快速回复:vb 将计算出的数据添加到txt文件中
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051882 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved