| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2621 人关注过本帖
标题:读取文件并保存到另一文件里面(用VB)
只看楼主 加入收藏
ship118
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2007-9-1
收藏
得分:0 
回复:(slore)[em18]第一不要说自己垃圾……第二我推...
不好意思,又要打扰你了,现在出现一点问题想请教一下。第一:原来的文件不是有好几个“G41”吗?但是转换后只要求第一次出现的G41改为M32M37,后面出现的全部删除。
第二:当检测到字符串G00的时候,在这一行后面增加M35M50,但是要求第一次出现的后面不增加。不知道怎么解决,谢谢了。


Private Sub Command1_Click()
Dim i As Integer, AddM As Byte
Dim strLine As String, StrLines As String
Open "c:\3\1.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strLine
If strLine = "M08" Or strLine = "G40" Or strLine = "G41" Then
If strLine = "M08" Then strLine = "Slore" 'Slore可以换一个不存在的字符比如:Z
If strLine = "G40" Then strLine = "Slore"
If strLine = "G41" Then strLine = "Slore"

Else
If AddM = 2 Then strLine = strLine & "M45": AddM = 0
If AddM = 1 Then strLine = strLine & "M35M50": AddM = 2

If strLine = "M07" Then strLine = "M36M00": AddM = 1
If Left(strLine, 3) = "G00" Then strLine = strLine & "M33M35"
strLine = Format(i, "\N0000") & strLine
i = i + 2
End If
StrLines = StrLines & strLine & vbCrLf
Loop
Close #1

StrLines = Replace(StrLines, "I.", "I0.")
StrLines = Replace(StrLines, "J.", "J0.")
StrLines = Replace(StrLines, " ", "") '去掉字符串中的空格
StrLines = Replace(StrLines, "M02", "M34M45M30")
StrLines = Replace(StrLines, "N0000G21", "%10001")
StrLines = Replace(StrLines, "N0002G91", "N0002G92X0Y0")
StrLines = Replace(StrLines, "N0004G92X0Y0", "N0004G91")
StrLines = Replace(StrLines, "N0006F650", "N0006F650")
StrLines = Replace(StrLines, "N0008G00X1508.00Y714.31M33M35", "N0008G00X1508.00Y714.31") '按不同的文件作相应的修改
StrLines = Replace(StrLines, vbCrLf & "Slore", "") '将回车+Slore替换掉

Text1 = StrLines



MkDir ("c:\4")
Open "c:\4\2.txt" For Output As #1
Print #1, Text1
Close #1
End Sub

2007-09-19 15:16
快速回复:读取文件并保存到另一文件里面(用VB)
数据加载中...
 
   



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

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