回复:(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