求助:输入文件(两组文件)输出文件(整合到一组)
各位VB大神,小弟初学vb不久,有个问题急需帮助:
原文件格式是相关联的两组,需要将其整合到一组中去,应该不难,但是始终找不到好方法,请帮助下啊,谢谢。
原文件输入格式
TABLE: "JOINT"
Joint=4900 X=44.4744 Y=130.4345 Z=19.05
Joint=4901 X=62.3804 Y=115.1785 Z=19.05
Joint=4902 X=64.87758 Y=115.2972 Z=19.05
Joint=4903 X=67.37476 Y=115.416 Z=19.05
Joint=4904 X=72.36911 Y=115.6535 Z=19.05
Joint=4905 X=74.86629 Y=115.7722 Z=19.05
TABLE: "FRAME"
Frame=540 JointI=4903 JointJ=4901
Frame=541 JointI=4901 JointJ=4902
Frame=542 JointI=4902 JointJ=4905
Frame=543 JointI=4900 JointJ=4904
Frame=544 JointI=4904 JointJ=4903
Frame=545 JointI=4905 JointJ=4900
需要输出的格式
Frame=540 JointI=4903 X=67.37476 Y=115.416 Z=19.05 JointJ=4901 X=62.3804 Y=115.1785 Z=19.05
Frame=541 JointI=4901 X=62.3804 Y=115.1785 Z=19.05 JointJ=4902 X=64.87758 Y=115.2972 Z=19.05
Frame=542 JointI=4902 X=64.87758 Y=115.2972 Z=19.05 JointJ=4905 X=74.86629 Y=115.7722 Z=19.05
Frame=543 JointI=4900 X=44.4744 Y=130.4345 Z=19.05 JointJ=4904 X=72.36911 Y=115.6535 Z=19.05
Frame=544 JointI=4904 X=72.36911 Y=115.6535 Z=19.05 JointJ=4903 X=67.37476 Y=115.416 Z=19.05
Frame=545 JointI=4905 X=74.86629 Y=115.7722 Z=19.05 JointJ=4900 X=44.4744 Y=130.4345 Z=19.05 VB 文件处理
[解决办法]
将二个文件发上来.(我针对你的二个文件进行编程)
发的方法如下:
1. 找到一个 jpg图片. 如 F:\1.jpg
2.将要上传的二个文件压缩. 压缩后的文件放入 F:\2.rar
3.开始->运行->cmd
4.在Dos下输入 F 转到F盘
5.输入 copy /b 1.jpg + 2.rar
6.发贴,插入图片,将刚才的1.jpg上传发出来.
[解决办法]
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'输入格式in.txt
'TABLE: "JOINT"
'Joint=4900 X=44.4744 Y=130.4345 Z=19.05
'Joint=4901 X=62.3804 Y=115.1785 Z=19.05
'Joint=4902 X=64.87758 Y=115.2972 Z=19.05
'Joint=4903 X=67.37476 Y=115.416 Z=19.05
'Joint=4904 X=72.36911 Y=115.6535 Z=19.05
'Joint=4905 X=74.86629 Y=115.7722 Z=19.05
'
'TABLE: "FRAME"
'Frame=540 JointI=4903 JointJ=4901
'Frame=541 JointI=4901 JointJ=4902
'Frame=542 JointI=4902 JointJ=4905
'Frame=543 JointI=4900 JointJ=4904
'Frame=544 JointI=4904 JointJ=4903
'Frame=545 JointI=4905 JointJ=4900
'
'需要输出的格式out.txt
'Frame=540 JointI=4903 X=67.37476 Y=115.416 Z=19.05 JointJ=4901 X=62.3804 Y=115.1785 Z=19.05
'Frame=541 JointI=4901 X=62.3804 Y=115.1785 Z=19.05 JointJ=4902 X=64.87758 Y=115.2972 Z=19.05
'Frame=542 JointI=4902 X=64.87758 Y=115.2972 Z=19.05 JointJ=4905 X=74.86629 Y=115.7722 Z=19.05
'Frame=543 JointI=4900 X=44.4744 Y=130.4345 Z=19.05 JointJ=4904 X=72.36911 Y=115.6535 Z=19.05
'Frame=544 JointI=4904 X=72.36911 Y=115.6535 Z=19.05 JointJ=4903 X=67.37476 Y=115.416 Z=19.05
'Frame=545 JointI=4905 X=74.86629 Y=115.7722 Z=19.05 JointJ=4900 X=44.4744 Y=130.4345 Z=19.05
Private Sub Form_Load()
Const MAXL As Long = 100000
Dim JS(0 To MAXL) As String
Dim JI(0 To MAXL) As Long
Dim NJ As Long
Dim FS(0 To MAXL) As String
Dim NF As Long
Dim ln As String
Dim fi As Integer
Dim fo As Integer
Dim f As Long
Dim k As Long
Dim i As Long
Dim j As Long
NJ = 0
NF = 0
fi = FreeFile()
Open "C:\tmp\in.txt" For Input As #fi
Do
Line Input #fi, ln
If EOF(fi) Then Exit Do
If Left(ln, 6) = "Joint=" Then
JS(NJ) = ln
JI(NJ) = Val(Mid(ln, 7))
NJ = NJ + 1
If NJ >= MAXL Then Exit Do
End If
If Left(ln, 6) = "Frame=" Then
FS(NF) = ln
NF = NF + 1
If NF >= MAXL Then Exit Do
End If
Loop
Close #fi
fo = FreeFile()
Open "C:\tmp\out.txt" For Output As #fo
For f = 0 To NF - 1
k = InStr(FS(f), "JointI=")
If k = 0 Then Exit For
Print #fo, Mid(FS(f), 1, k + 6);
i = Val(Mid(FS(f), k + 7))
For j = 0 To NJ - 1
If JI(j) = i Then
Print #fo, Mid(JS(j), 7); " ";
Exit For
End If
Next
k = InStr(FS(f), "JointJ=")
If k = 0 Then Exit For
Print #fo, " JointJ=";
i = Val(Mid(FS(f), k + 7))
For j = 0 To NJ - 1
If JI(j) = i Then
Print #fo, Mid(JS(j), 7)
Exit For
End If
Next
Next
Close #fo
End
End Sub
'实际运行c:\tmp\out.txt文件内容为:
'Frame=540 JointI=4903 X=67.37476 Y=115.416 Z=19.05 JointJ=4901 X=62.3804 Y=115.1785 Z=19.05
'Frame=541 JointI=4901 X=62.3804 Y=115.1785 Z=19.05 JointJ=4902 X=64.87758 Y=115.2972 Z=19.05
'Frame=542 JointI=4902 X=64.87758 Y=115.2972 Z=19.05 JointJ=4905 X=74.86629 Y=115.7722 Z=19.05
'Frame=543 JointI=4900 X=44.4744 Y=130.4345 Z=19.05 JointJ=4904 X=72.36911 Y=115.6535 Z=19.05
'Frame=544 JointI=4904 X=72.36911 Y=115.6535 Z=19.05 JointJ=4903 X=67.37476 Y=115.416 Z=19.05