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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Mask in VB.NET

Status
Not open for further replies.

Tamrak

MIS
Jan 18, 2001
213
US
Good afternoon,

I am very brand new to the VB.net. I have questions regarding input mask.

In Microsoft Access, we can set an input ask for each field that we created. For example, the input mask for the date might be "_ _ /_ _ /_ _" . The user can input the date right away. The dashes and slashes do not move or disappear.

When I tried to work this one in the VB, I created a text field. But I could not locate anything in the property that I can default the mask. I did created a sub for this field. The field name is txtbDate, from the textbox.

*********************
Private Sub MDate

Dim mbDate as Date

Txtbdate.Text() = format(mbDate,"_ _ /_ _ /_ _")

End Sub

****************************

When I tried to input the date in there, the dashes and slashes disappeared.

How can I make the default "_ _ /_ _ /_ _", without having the dashes and slashes disappeared? User needs to type only the date month and year.

I realize that I might be wrong on several things. Your comments are welcome. I am new to this VB. Thanks.


 
in the validating event of the text box you could put

try
txtbdate.text = format(cdate(txtbdate.text),"dd/MM/yyyy")
catch
'the date entered could not be comverted to a date/time string
msgbox"Invalid date format")
e.cancel = true
end try

the format function works slightly differently to an input mask, see the help for details regarding the different formats availiable.

The above will attempt to convert the text entered into a date/time using cDate()

If it fails the entry will be invalidated and the user is forced to stay in the textbox until they enter a valid date.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top