📄 modwordprocess.bas
字号:
Attribute VB_Name = "modWordProcess"
'============================================================
'|| ||
'|| 由服务器返回的数据库查询记录字符串 处理模块 ||
'|| (通用) ||
'|| ||
'============================================================
Option Explicit
'GetInString 函数返回的自定义类型
Public Type WordNode
strGet As String '特定的子字符串
lngNextStart As Long '下一位置
End Type
'=======================================================
' 功能描述:
' 返回从strSrc字符串中的lngStart位置开始到strStopChr字符
'之间的子字符串和strStopChr字符的下一个位置
'=======================================================
Public Function GetInString(ByVal strSrc As String, _
ByVal lngStart As Long, _
ByVal strStopChr As String) As WordNode
Dim strTp As String, strTp1 As String * 1
Dim lngNextSt As Long
Dim blnOutMaxLen As Boolean '是否超出源字符串的长度
strTp = ""
blnOutMaxLen = False
strTp1 = Mid(strSrc, lngStart, 1)
lngNextSt = lngStart
While strTp1 <> strStopChr And Not blnOutMaxLen
strTp = strTp + strTp1
lngNextSt = lngNextSt + 1
If lngNextSt > Len(strSrc) Then blnOutMaxLen = True '超出源字符串的长度
strTp1 = Mid(strSrc, lngNextSt, 1)
Wend
lngNextSt = lngNextSt + 1
GetInString.lngNextStart = lngNextSt
GetInString.strGet = strTp
End Function
'=======================================================
' 功能描述:
' 返回数据库查询记录字符串中的字段名称个数
' 入口参数:
' strSrc 源字符串
' strFdDivRst 字符串中字段名称和记录内容的分隔符
' strFdRd 字符串中字段名称之间、记录内容各字段之间的分隔符
'=======================================================
Public Function GetFieldsCount(ByVal strSrc As String, _
ByVal strFdRd As String, _
ByVal strFdDivRst As String) As Integer
Dim intTp As Integer, intN As Integer
Dim strTp As String * 1
intTp = 0
strTp = Mid(strSrc, 1, 1)
intN = 1
While strTp <> strFdDivRst
If strTp = strFdRd Then intTp = intTp + 1
intN = intN + 1
strTp = Mid(strSrc, intN, 1)
Wend
GetFieldsCount = intTp + 1
End Function
'=================================================================
' 功能描述:
' 将数据库查询记录字符串复原显示在 MSFlexGrid 控件中
' 入口参数:
' ctlFgd MSFlexGrid控件名称
' strRecordSet 由服务器返回的数据库查询记录字符串
' strFdRd 字符串中字段名称之间、记录内容各字段之间的分隔符
' strFdDivRst 字符串中字段名称和记录内容的分隔符
' *注意:包含MSFlexGrid控件的窗体一定要以 缇 为单位(ScaleMode= 1-Twip)
'=================================================================
Public Sub MSFlexGridDispRecordSet(ByVal ctlFgd As MSFlexGrid, _
ByVal strRecordSet As String, _
ByVal strFdRd As String, _
ByVal strFdDivRst As String)
Dim strTp As String
Dim wndTp As WordNode
Dim intNextStart As Integer, intRow As Integer, intCol As Integer
Dim intFeildCount As Integer
Dim lngLenStrRst As Long
intFeildCount = GetFieldsCount(strRecordSet, strFdRd, strFdDivRst)
lngLenStrRst = Len(strRecordSet)
With ctlFgd
.FixedCols = 0 '没有固定列
.FixedRows = 1 '只有一个固定行,显示字段名称
.Cols = intFeildCount '总列数
.Rows = 1 '当前总行数(可变)
.AllowUserResizing = flexResizeBoth '允许调整单元格大小
.ScrollBars = flexScrollBarBoth '允许出现水平、垂直滚动条
End With
intNextStart = 1
intRow = 0
ctlFgd.Row = intRow
strTp = GetInString(strRecordSet, 1, strFdDivRst).strGet
intFeildCount = intFeildCount - 1
'平均分配各列的宽度,注意:colWidth只能以 缇 为单位
For intCol = 0 To intFeildCount
ctlFgd.ColWidth(intCol) = ctlFgd.Width / (intFeildCount + 1)
Next intCol
'显示各个字段名称
For intCol = 0 To intFeildCount
ctlFgd.Col = intCol
wndTp = GetInString(strTp, intNextStart, strFdRd)
ctlFgd.Text = wndTp.strGet
intNextStart = wndTp.lngNextStart
Next intCol
'显示记录内容
While intNextStart < lngLenStrRst
ctlFgd.Rows = ctlFgd.Rows + 1
intRow = intRow + 1
ctlFgd.Row = intRow
For intCol = 0 To intFeildCount
ctlFgd.Col = intCol
wndTp = GetInString(strRecordSet, intNextStart, strFdRd)
ctlFgd.Text = wndTp.strGet
intNextStart = wndTp.lngNextStart
Next intCol
Wend
End Sub
'=================================================================
' 功能描述:
' 将数据库查询记录字符串复原显示在 ListView 控件中(Report视图)
' 入口参数:
' ctlLvw ListView控件名称
' strRecordSet 由服务器返回的数据库查询记录字符串
' strFdRd 字符串中字段名称之间、记录内容各字段之间的分隔符
' strFdDivRst 字符串中字段名称和记录内容的分隔符
'=================================================================
Public Sub ListViewDispRecordSet(ByVal ctlLvw As ListView, _
ByVal strRecordSet As String, _
ByVal strFdRd As String, _
ByVal strFdDivRst As String)
Dim intFeildCount As Integer, intCol As Integer, intRow As Integer
Dim lngLenStrRst As Long
Dim strTp As String
Dim wndTp As WordNode
Dim intNextStart As Integer
Dim LstItmTp As ListItem
intFeildCount = GetFieldsCount(strRecordSet, strFdRd, strFdDivRst)
lngLenStrRst = Len(strRecordSet)
ctlLvw.View = lvwReport 'Report视图
intNextStart = 1
strTp = GetInString(strRecordSet, 1, strFdDivRst).strGet
'显示各个字段名称
For intCol = 1 To intFeildCount
wndTp = GetInString(strTp, intNextStart, strFdRd)
ctlLvw.ColumnHeaders.Add , "lvw" + CStr(intCol), wndTp.strGet, ctlLvw.Width / (intFeildCount + 1)
intNextStart = wndTp.lngNextStart
Next intCol
'显示记录内容
intRow = 0
intFeildCount = intFeildCount - 1
While intNextStart < lngLenStrRst
intRow = intRow + 1
For intCol = 0 To intFeildCount
wndTp = GetInString(strRecordSet, intNextStart, strFdRd)
If intCol = 0 Then
Set LstItmTp = ctlLvw.ListItems.Add(, "lvw" + CStr(intRow) + CStr(intCol), wndTp.strGet)
Else
LstItmTp.SubItems(intCol) = wndTp.strGet
End If
intNextStart = wndTp.lngNextStart
Next intCol
Wend
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -