我写了个模块函数,用来把sql数据库导出成txt文件,出来效果是每一列之间都会有一个空格间隔,例如:0052135199011 赵燕梅
0052423253011 赵同晃
0065310602011 吴伟庭
0063829765011 陈文利 我不想要这个空格如:0052135199011赵燕梅
0052423253011赵同晃
0065310602011吴伟庭
0063829765011陈文利 以下是函数内容,请各位大大指教,应该怎么改才能达到要求,谢谢。Public Function TabintoTxt(objConn As Object, TableName As String, Optional TextFileName As String)
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
Dim i As Long
Dim s As String
Dim imax As Integer
Dim WritStr As String
Dim writstry() As String
Dim Fid As Long
Dim lngCount As Long ' 计数。 If TextFileName = "" Then
If Month(Date) < 10 Then
TextFileName = "e:\data\" & "sf" & Year(Date) & "0" & Month(Date) - 1 & ".txt"
Else
TextFileName = "e:\data\" & "sf" & Year(Date) & Month(Date) - 1 & ".txt"
End If
End If
If objConn.State = 0 Then objConn.Open
rs.Open "select * from " + TableName, objConn Fid = FreeFile
rs.MoveFirst
Open TextFileName For Output As #Fid
ReDim writstry(rs.Fields.Count - 1)
While Not rs.EOF
'writstry(0) = Format(Trim(rs(0)), "!@@@@@@@@@@@@@")
writstry(0) = Trim(rs.Fields(0))
writstry(1) = LTrim(rs.Fields(1))
writstry(2) = Format(Trim(rs(2)), String(8, "@"))
writstry(3) = Format(Trim(rs(3)), "@@@@@@@ ")
writstry(4) = Format(Trim(rs(4)), "@")
Print #Fid, Join(writstry)
rs.MoveNext
lngCount = lngCount + 1
Wend
Close #Fid
rs.Close
MsgBox "导出 " & Format(lngCount) & " 笔记录。"
End Function
0052423253011 赵同晃
0065310602011 吴伟庭
0063829765011 陈文利 我不想要这个空格如:0052135199011赵燕梅
0052423253011赵同晃
0065310602011吴伟庭
0063829765011陈文利 以下是函数内容,请各位大大指教,应该怎么改才能达到要求,谢谢。Public Function TabintoTxt(objConn As Object, TableName As String, Optional TextFileName As String)
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
Dim i As Long
Dim s As String
Dim imax As Integer
Dim WritStr As String
Dim writstry() As String
Dim Fid As Long
Dim lngCount As Long ' 计数。 If TextFileName = "" Then
If Month(Date) < 10 Then
TextFileName = "e:\data\" & "sf" & Year(Date) & "0" & Month(Date) - 1 & ".txt"
Else
TextFileName = "e:\data\" & "sf" & Year(Date) & Month(Date) - 1 & ".txt"
End If
End If
If objConn.State = 0 Then objConn.Open
rs.Open "select * from " + TableName, objConn Fid = FreeFile
rs.MoveFirst
Open TextFileName For Output As #Fid
ReDim writstry(rs.Fields.Count - 1)
While Not rs.EOF
'writstry(0) = Format(Trim(rs(0)), "!@@@@@@@@@@@@@")
writstry(0) = Trim(rs.Fields(0))
writstry(1) = LTrim(rs.Fields(1))
writstry(2) = Format(Trim(rs(2)), String(8, "@"))
writstry(3) = Format(Trim(rs(3)), "@@@@@@@ ")
writstry(4) = Format(Trim(rs(4)), "@")
Print #Fid, Join(writstry)
rs.MoveNext
lngCount = lngCount + 1
Wend
Close #Fid
rs.Close
MsgBox "导出 " & Format(lngCount) & " 笔记录。"
End Function
解决方案 »
- 请问我没有用扩展控件,为什么在别的机器上运行我的程序会出现runtime error 380?
- VB高手请进来!这个功能怎么实现?
- SQLSERVER2000数据库维护的问题(很弱)?
- 在SQL-SERVER中将表导入导出时,丢失ID的IDENTITY属性(自动增加),能否自动??
- 100分奉上!哪里有VB关于类模块的电子书籍!
- date()奇怪的问题??
- 有高手帮忙写个股票软件实时数据读取的程序吗?价格面议
- spread控件上的action是什麼意思
- 关于ADO中的recordset对象的排序方法(很急)
- C做的dll被 VB 程序调用
- 求助VB读温控表的版本号为什么没反应
- VB SQL3.5数据库修改
list 必需的。包含被连接子字符串的一维数组。
delimiter 可选的。在返回字符串中用于分隔子字符串的字符。如果忽略该项,则使用空格(" ")来分隔子字符串。如果delimiter是零长度字符串(""),则列表中的所有项目都连接在一起,中间没有分隔符。