Private Sub Command1_Click() Dim Coll As New Collection Dim K() As String Dim T() As String Dim I As Integer Dim ID As Integer
On Error Resume Next
ID = 0 K = Split("1,2,4,3,5,6,7,8,9,8,7,0,2,3,45,8", ",") For I = 0 To UBound(K) Err.Clear Coll.Add K, "T" & K(I) If Err.Number = 0 Then ReDim Preserve T(ID) T(ID) = K(I) ID = ID + 1 End If Next
For I = 0 To UBound(T) Debug.Print T(I) NextEnd Sub
TO:MSTOP(陈建华) 1、文件里的值是非常多行的! 2、我原来是用: Open Temp.Text For Input As #10 Line Input #10, A3 3、Debug.Print 是什么意思?
Debug.Print 是在立即窗口(按Ctrl+G弹出)打印内容
Debug.Print 都是用来调式程序和检查数据是否有逻辑错误的 立即窗口 显示值
TO: faysky2() 和 ZOU_SEAFARER(国际海员) 我的问题您们会吗?谢谢!
'记录多的话,把Txt文件当作数据库来操作能快一些 '需要引用ADO("工程"/"引用"/Microsoft ActiveX Data Object 2.X Library) Private Sub Command6_Click() Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim strTmp As String cn.CursorLocation = adUseClient cn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=C:\;Extensions=asc,csv,tab,txt;"
Set rs = cn.Execute("select distinct * From test.txt") '得到不重复的记录 rs.MoveFirst While Not rs.EOF strTmp = strTmp & rs(0) & vbCrLf rs.MoveNext Wend Open "c:\test.txt " For Output As #1 '清楚文件内容 Close #1 Open "C:\test.txt" For Binary As #1 '写入新内容(不重复的记录) Put #1, 1, strTmp Close #1
rs.Close cn.Close Set rs = Nothing Set cn = Nothing End Sub
to lsftest:你看是不是可以考虑: select distinct * From test.txt into 到一个临时文本文件,然后用临时文件覆盖原文件
to lsftest:你看是不是可以考虑: select distinct * From test.txt into 到一个临时文本文件,然后用临时文件覆盖原文件 ======================================== 这样等于是在操作两个数据库就这么into 到一个临时文本文件语句上应该怎么写?? 在sql server可以用dts,但文本文件没试过。不知道可不可以
to lsftest:你看是不是可以考虑: select distinct * From test.txt into 到一个临时文本文件,然后用临时文件覆盖原文件 ======================================== 这样等于是在操作两个数据库就这么into 到一个临时文本文件语句上应该怎么写?? 在sql server可以用dts,但文本文件没试过。不知道可不可以========================================select distinct a.* into [TEXT;Database=C:\].2.txt from [TEXT;Database=C:\].1.txt as A其中1.txt是源文本文件,2.txt是新生成的文本文件。
Dim Coll As New Collection
Dim K() As String
Dim T() As String
Dim I As Integer
Dim ID As Integer
On Error Resume Next
ID = 0
K = Split("1,2,4,3,5,6,7,8,9,8,7,0,2,3,45,8", ",")
For I = 0 To UBound(K)
Err.Clear
Coll.Add K, "T" & K(I)
If Err.Number = 0 Then
ReDim Preserve T(ID)
T(ID) = K(I)
ID = ID + 1
End If
Next
For I = 0 To UBound(T)
Debug.Print T(I)
NextEnd Sub
1、文件里的值是非常多行的!
2、我原来是用:
Open Temp.Text For Input As #10
Line Input #10, A3
3、Debug.Print 是什么意思?
立即窗口 显示值
我的问题您们会吗?谢谢!
'需要引用ADO("工程"/"引用"/Microsoft ActiveX Data Object 2.X Library)
Private Sub Command6_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strTmp As String
cn.CursorLocation = adUseClient
cn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=C:\;Extensions=asc,csv,tab,txt;"
Set rs = cn.Execute("select distinct * From test.txt") '得到不重复的记录
rs.MoveFirst
While Not rs.EOF
strTmp = strTmp & rs(0) & vbCrLf
rs.MoveNext
Wend
Open "c:\test.txt " For Output As #1 '清楚文件内容
Close #1
Open "C:\test.txt" For Binary As #1 '写入新内容(不重复的记录)
Put #1, 1, strTmp
Close #1
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
================
会有多长(多少行)???
如果数据格式统一,可以把这个文件作为数据源用带Distinct的sql查询语句读入到程序里,然后重新生成一个txt文件好处是不必自己写代码判断,而且如果要对结果排序也可以由sql语句代劳。
select distinct * From test.txt into 到一个临时文本文件,然后用临时文件覆盖原文件
select distinct * From test.txt into 到一个临时文本文件,然后用临时文件覆盖原文件
========================================
这样等于是在操作两个数据库就这么into 到一个临时文本文件语句上应该怎么写??
在sql server可以用dts,但文本文件没试过。不知道可不可以
用excel来打开这个文本文件然后保存成一个新的独立的xls文件,然后就可以用常规方法查询sheet1的数据最后把结果写入到sheet2至于结果是否保存回到txt或csv文件就看楼主的实际需要
select distinct * From test.txt into 到一个临时文本文件,然后用临时文件覆盖原文件
========================================
这样等于是在操作两个数据库就这么into 到一个临时文本文件语句上应该怎么写??
在sql server可以用dts,但文本文件没试过。不知道可不可以========================================select distinct a.* into [TEXT;Database=C:\].2.txt from [TEXT;Database=C:\].1.txt as A其中1.txt是源文本文件,2.txt是新生成的文本文件。