Is there any way to easily right allign a masked edit box?
Printable View
Is there any way to easily right allign a masked edit box?
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