VB如何保存数据到文件中。
现在有一个text文本文件中有大量这样的记录:"1C00000005435129-7",11/16/201018:05:33,+08:00,54,,0.0,0,,,,,,...
现在有一个text文本文件中有大量这样的记录:
"1C00000005435129-7",11/16/2010 18:05:33,+08:00,54,,0.0,0,,,,,,,,,781536.8,,,,,,,,
"1C00000005435129-7",11/11/2010 19:05:33,+08:00,54,,0.0,0,,,,,,,,,781536.8,,,,,,,,
"1C00000005435129-6",11/16/2010 18:05:39,+08:00,54,,0.0,0,,,,,,,,,780174.0,,,,,,,,
"1C00000005435129-5",11/16/2010 18:05:45,+08:00,54,,0.0,0,,,,,,,,,781883.7,,,,,,,,
"1C00000005435129-4",11/16/2010 18:05:51,+08:00,54,,0.0,0,,,,,,,,,779993.5,,,,,,,,
我现在要把第一个字段,如:
"1C00000005435129-7"
"1C00000005435129-6"
"1C00000005435129-5"
"1C00000005435129-4"
保存到一个另外一个text文件中去(注意,第一个字段值有些是相同的,要过滤掉相同的),请问如何实现。 展开
"1C00000005435129-7",11/16/2010 18:05:33,+08:00,54,,0.0,0,,,,,,,,,781536.8,,,,,,,,
"1C00000005435129-7",11/11/2010 19:05:33,+08:00,54,,0.0,0,,,,,,,,,781536.8,,,,,,,,
"1C00000005435129-6",11/16/2010 18:05:39,+08:00,54,,0.0,0,,,,,,,,,780174.0,,,,,,,,
"1C00000005435129-5",11/16/2010 18:05:45,+08:00,54,,0.0,0,,,,,,,,,781883.7,,,,,,,,
"1C00000005435129-4",11/16/2010 18:05:51,+08:00,54,,0.0,0,,,,,,,,,779993.5,,,,,,,,
我现在要把第一个字段,如:
"1C00000005435129-7"
"1C00000005435129-6"
"1C00000005435129-5"
"1C00000005435129-4"
保存到一个另外一个text文件中去(注意,第一个字段值有些是相同的,要过滤掉相同的),请问如何实现。 展开
2个回答
展开全部
可以不用vb实现。把你的文件改名为excel文件可以识别的格式,如“text1.csv”,用excel打开,删除其它列,只保留第一列,另存,再把文件的名字改回来。
用vb实现(假设你的文件存在 d:\):
Private Sub Command1_Click()
Dim j As Integer, k As Integer
Dim A As String, B As String, C As String
Open "d:\text1.txt" For Input As #1
Open "d:\text2.txt" For Output As #2
While Not EOF(1)
Line Input #1, A
k = Len(A)
For j = 1 To k
B = Mid(A, j, 1)
If B = "," Then
C = Mid(A, 1, j - 1)
Print #2, C
GoTo 10
End If
Next j
10 '
Wend
Close #1
Close #2
MsgBox "ok"
End Sub
用vb实现(假设你的文件存在 d:\):
Private Sub Command1_Click()
Dim j As Integer, k As Integer
Dim A As String, B As String, C As String
Open "d:\text1.txt" For Input As #1
Open "d:\text2.txt" For Output As #2
While Not EOF(1)
Line Input #1, A
k = Len(A)
For j = 1 To k
B = Mid(A, j, 1)
If B = "," Then
C = Mid(A, 1, j - 1)
Print #2, C
GoTo 10
End If
Next j
10 '
Wend
Close #1
Close #2
MsgBox "ok"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询