文本框两端对齐
时 间:2020-11-06 18:01:18
作 者:猫猫 ID:28985 城市:北京
摘 要:textbox文本框字符串两端对齐,看看哪位大神再给改进改进。
正 文:
'利用access textbox(64位) 分散对齐,空值每行数量,并处理文本中部分符号及尾部对齐。需要自己确定文本长度。
Function GetCharLen(pChar() As Byte) As Long
GetCharLen = 1 - (pChar(1) <> 0)
End Function
Dim myStr As String
Dim Length As Long
Dim arrStr() As String
Dim tmpLen As Long
Dim tmpBit As Long
Dim Idx As Long
Dim i As Long
Dim Fcharacters As Variant
Dim TempByte() As Byte
Dim Nullspaces As Integer
Dim Numvalues As Variant
On Error GoTo dygs_Err
Fcharacters = ",.:;?:,。;、!:?" '开头不可以出现的符号********
myStr = text_name
Length = Len(myStr)
ReDim arrStr(Length * 2)
For i = 1 To Length
tmpBit = i
tmpLen = 0
Do
tmpLen = tmpLen + GetCharLen(Mid(myStr, i, 1))
i = i + 1
Loop Until tmpLen >= number or i > Length
If tmpLen > number Then i = i - 1
If InStr(Fcharacters, Right(Mid(myStr, tmpBit, i - tmpBit + 1), 1)) <> 0 And _
InStr(Fcharacters, Left(Mid(myStr, tmpBit, i - tmpBit), 1)) <> 0 Then
arrStr(Idx) = Mid(myStr, tmpBit + 1, i - tmpBit + 1)
Else
If InStr(Fcharacters, Right(Mid(myStr, tmpBit, i - tmpBit + 1), 1)) <> 0 Then
arrStr(Idx) = Mid(myStr, tmpBit, i - tmpBit + 1)
Else
If InStr(Fcharacters, Left(Mid(myStr, tmpBit, i - tmpBit), 1)) <> 0 Then
arrStr(Idx) = Mid(myStr, tmpBit + 1, i - tmpBit)
Else
arrStr(Idx) = Mid(myStr, tmpBit, i - tmpBit)
End If
End If
End If
Idx = Idx + 1
i = i - 1
Next i
ReDim Preserve arrStr(Idx)
'尾端数据对齐,判断数组最后一行字符串数量并添加空值。
TempByte = Mid(myStr, tmpBit, i)
If (UBound(TempByte) + 1) > number Then
Nullspaces = number - (UBound(TempByte) + 1) Mod number
Else
Nullspaces = number - (UBound(TempByte) + 1)
End If
For Z = 1 To Nullspaces
Numvalues = Numvalues & Chr(2)
Next
AlignBothEnds = Left(Join(arrStr, vbCrLf), Len(Join(arrStr, vbCrLf)) - 1) & Numvalues
dygs_Exit:
Exit Function
dygs_Err:
MsgBox Error$
Resume dygs_Exit
End Function
Private Sub Command1_Click()
Text2 = AlignBothEnds(Text1, 63)
End Sub
附 件:
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 统计当月之前(不含当月)的记录...(03.11)
- 【Access Inputbo...(03.03)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- 【Access Inputbo...(12.23)
- 【Access Dsum示例】...(12.16)

学习心得
最新文章
- 仓库管理实战课程(7)-创建查询(03.31)
- 仓库管理实战课程(6)-创建查询(03.29)
- 仓库管理实战课程(5)-字段属性(03.27)
- 设备装配出入库管理系统;基于Acc...(03.24)
- 仓库管理实战课程(4)-建表操作(03.22)
- 仓库管理实战课程(3)-需求设计说...(03.19)
- 仓库管理实战课程(2)-软件背景和...(03.18)
- 仓库管理实战课程(1)-讲师介绍(03.16)
- 统计当月之前(不含当月)的记录数怎...(03.11)
- 【Access Inputbox示...(03.03)