Results 1 to 2 of 2

Thread: Allignment

  1. #1

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249

    Allignment

    Is there any way to easily right allign a masked edit box?
    Normal is boring...

    smh

  2. #2
    Matthew Gates
    Guest
    Well, the MaxLength of a MaskEdBox Control is 64, so say you were to set the code below to 45, that would leave you with only 19 characters.

    But if you still want to use it, here is the code.


    Code:
    'Submitted by:  Nich Shamas
    
    Public Function vAutoAlign(strText As String, Optional vAlign As Integer = 0, Optional vMaxLength As Long = 92) As String
        Dim sLen As Long
        sLen = Len(strText)
    
        If sLen >= Val(vMaxLength) Then
            vAutoAlign = strText
            Exit Function
        End If
    
        If vAlign <= 0 Then 'center align
            vAutoAlign = String((Val(vMaxLength) - sLen) / 2, " ") & strText
        ElseIf vAlign >= 1 Then 'right align
            vAutoAlign = String(Val(vMaxLength) - sLen, " ") & strText
        End If
    End Function
    
    
    Private Sub Form_Load()
        MaskEdBox1.Text = vAutoAlign(MaskEdBox1.Text, vbAlignRight, 45)
        MaskEdBox1.SelStart = Len(MaskEdBox1.Text)
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width