How to Right Justify Standard Numbers in a Masked Edit FieldID: Q97141
|
The Masked edit control does not provide a method to right justify numbers.
Ordinary methods and the Format$ function do not work because the Masked
edit control uses the underscore character to represent blanks in the text
property. For example, if 300 is entered in a Masked edit field with a mask
of #####, the text property would contain "__300" instead of " 300."
However, you can use the technique described in this article to right
justify a Masked edit field using a standard number mask and format. This
is done in three steps:
The following example demonstrates this process:
Default Name Caption Mask Format
------------------------------------------------
MaskedEdit1 (Not applicable) #### ####
Command1 Right Justify
' Ensure that the string is not already right-justified.
If InStr((Len(MaskedEdit1.Text)), MaskedEdit1.Text, "_") =
Len(MaskedEdit1.Text) Then
' The first String$ function creates the underscore string. The
' Format$ trims the text property of the MaskedEdit control.
' Enter the following two lines as one, single line:
MaskedEdit1.text = Right$(String$(Len(MaskedEdit1.Text), "_") &
Format$(Val(MaskedEdit1.Text)), Len(MaskedEdit1.Text))
End If
Additional query words: 2.00 3.00 alignment align right-align
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 10, 1999