• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 596
  • Last Modified:

MaskedTextBox removes preceding 0

I have a masked text box, for Birthdate. In the when grabbing and formatiing the data it is a date with preceeding zero's if necessary (05/05/2005)

However when it gets inseted into the masked text box it converts the aboexample date to look like 55/20/05__

The mask on the text box is 00/00/0000

Is there some way to get this to work correctly?
0
kikimayhay
Asked:
kikimayhay
  • 4
  • 2
  • 2
  • +1
5 Solutions
 
srikanthreddyn143Commented:
one way could be format the date as string with format(MM/dd/yyyy).Try it out.
0
 
magicdlfCommented:
http://homepage.ntlworld.com/herring1/format.html
Dates and the MaskedTextBox

I used the supplied date masks and was a little surprised that these did not perform any validation at all, for example you could enter a date of '22/75/0000' or even leave part of the date blank. However, when I looked at the Microsoft Developer Network website this was explained very well and there was a good example. So I decided to try a custom mask calling events as suggested. This works very well and gives as much flexibility in your validation as most people would ever need. It seems a bit of a shame that these weren't incorporated directly into the control. Never mind it has made me re-evaluate my approach to data validation.
0
 
magicdlfCommented:
So how did you input your data 5/5/2005? Copy paste? Manually input? or by a program?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kikimayhayAuthor Commented:
The Data is coming from a date field in a database table the line that assigns it is:
MaskedTextBox.text = Format(datatable(0)("DOB"), "MM/dd/yyyy")
and I get results as stated above
0
 
planoczCommented:
I have not had time to test this but you may want to do this
MaskedTextBox.text = Format(datatable(0)("DOB"), "MM/dd/yyyy").ToString

0
 
kikimayhayAuthor Commented:
I've tried that as well, the really weird thing is I have the same control on another form  in the same program. It pulls the same data from the same table, and is formatted the same, yet somehow it works as intended.
0
 
planoczCommented:
I have seen that happen before in other controls.
Had to delete the control and re-add it again.
0
 
kikimayhayAuthor Commented:
Deleting and re-adding the control did not work. I had to delete the form and manually re-add all the controls (copy and pasting logic behind controls).  
I cannot recreate the behaviour. Not sure what was going on but it had to be somewhere within the form itself.
0
 
kikimayhayAuthor Commented:
Dispursing evenly among comments
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now