文本框两端对齐-猫猫
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-报表


文本框两端对齐

发表时间:2020/11/6 18:01:18 评论(1) 浏览(3742)  评论 | 加入收藏 | 复制
   
摘 要:textbox文本框字符串两端对齐,看看哪位大神再给改进改进。
正 文:
'========================================================
'利用access textbox(64位) 分散对齐,空值每行数量,并处理文本中部分符号及尾部对齐。需要自己确定文本长度。
Function GetCharLen(pChar() As Byte) As Long
    GetCharLen = 1 - (pChar(1) <> 0)

End Function


Function AlignBothEnds(text_name As Variant, number As Integer)
    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群(群号:198465573)
 
 相关文章
access 2007文本对齐或居中  【Microsoft  2008/3/12】
如何在列表框中让金额变得更美观,金额靠右显示,数字靠右显示  【第7天  2008/3/14】
一句话解释access小技巧之:access光标为什么会在文本框右...  【麥田  2012/8/8】
选项卡里多个子窗体如何用代码来实现边距大小对齐  【杜超  2016/7/18】
用代码实现表字段对齐  【杜超  2016/9/5】
窗体上控件对齐  【qwse  2017/11/26】
常见问答
技术分类
相关资源
文章搜索
关于作者

猫猫

文章分类

文章存档

友情链接