Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Masks for TextBoxes

Status
Not open for further replies.

JaeBrett

Programmer
May 5, 2003
196
CN
I have a few textboxes where users type in dates. Is there a way to put an input mask on that textbox to force the proper format ???


Thanks.
 
Masked Edit Box control? It's in MSMASK32.OCX Usage instructions are in VBHelp


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
The best way to get date input is to use the DateTimePicker that comes with the WindowsCommon Controls OCX shipped with VB. You'll find it in the components gallery under "Microsoft Windows Common Controls 2" (or maybe 3?)
 
I agree - but that wasn't the question! [lol]


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
i try to avoid this particular control. i generally find it doesn't act as i want it to (of course, i may be misunderstanding how it works!)

you may find this code useful. i use it with ordinary textboxes whose maxlen is set to 8 (dd/mm/yy). it allows a user to only input numeric characters and the "/" appears automatically in the correct place. i don't use placeholders, but that could be coded in. finally, i check that the date is valid (don't rely on IsDate - you may get unexpected results) - but that validation isn't here.

Private Sub DateMask(ctl As Control, KeyAscii As Integer)
'because vb's mask control is not up to the task

Dim strChar As String * 1
strChar = Chr(KeyAscii)
If KeyAscii = 47 Or KeyAscii = 46 Then KeyAscii = 0 'cancel a user-input "/" or "."
If IsNumeric(strChar) Then
If Len(ctl) = 1 Or Len(ctl) = 4 Then
KeyAscii = 0
ctl = ctl & strChar & "/"
ctl.SelStart = Len(ctl)
End If
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top