nbsp; Case dbTimeStamp
getFmt = "@@@@@@@@@@"
End Select
End Function
---- 第二步,取结果集的内容并根据各列的格式字符串生成表格,生成的表格存放在字符串数组 strDy()中,下面用Sub Dy()例示这一步骤。
Dim strDy() As String
注释:存放格式化后的表格内容
Dim Fmt() As String
注释:存放表格各列的格式字符串
注释:以上二个数组变量的元素个数根
据结果集的行数和列数在
程序中设定
Dim str,str0,str1,str2 As String
注释:临时使用的串变量
Dim i,j As Integer
注释:临时使用的整型变量
Dim intDc As Integer 注释:存放表格行数,
实际上即是strDy()的元素个数
Private Sub Dy()
With MyData.Recordset
.MoveLast
ReDim strDy(.RecordCount + 8)
注释:需存放标题、表框等,所以加8
ReDim Fmt(.Fields.Count)
For i = 0 To .RecordCount + 7
strDy(i) = "" 注释:初始置空
Next
For i = 0 To .Fields.Count - 1
Fmt(i) = getFmt(.Fields(i).Type, .Fields(i).Size)
注释:生成表格各列的格式字符串
j = Len(.Fields(i).Name)
If j > Len(Fmt(i)) Then
Fmt(i) = String$(Int((j / 2) + 0.5) * 2, "@")
注释:标题 (字段名) 字多则增大列宽
End If
Next
str = "┃"
str0 = "┏"
str1 = "┠"
str2 = "┗" 注释:设定表格为粗框细线,
可根据需要改变
For i = 0 To .Fields.Count - 1
For j = 1 To Len(Fmt(i)) / 2
str0 = str0 & "━"
str1 = str1 & "─"
str2 = str2 & "━"
Next
If (i = .Fields.Count - 1) Then
str = str & Format(.Fields(i).Name, Fmt(i)) & "┃"
Else
str = str & Format(.Fields(i).Name, Fmt(i)) & "│"
End If
If (i = .Fields.Count - 1) Then
str0 = str0 & "┓"
str1 = str1 & "┨"
str2 = str2 & "┛"
Else
str0 = str0 & "┯"
str1 = str1 & "┼"
str