Solved

Formatting a Textbox

Posted on 2006-10-27
3
197 Views
Last Modified: 2010-04-23
Hi all,

I have a textbox on my form and I would like the user to enter 4 numbers into it and have the textbox automatically format it to xx/xx as they are typing. I have tried using the below code but when I do once the first two numbers have been typed the cursor is moved back to the start of the box rather than after the "/"

If txtboxExp.Text.Length = 2 Then
       txtboxExp.Text = txtboxExp.Text & "/"
End If

Can someone let me know and easy way of creating a custom format for a textbox like this.
Thanks
0
Comment
Question by:kiranboi
3 Comments
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 17818888
Try this:

            If txtboxExp.Text.Length = 2 Then
                  txtboxExp.Text = txtboxExp.Text & "/"
                  txtboxExp.SelectionStart = txtboxExp.Text.Length
            End If
0
 

Author Comment

by:kiranboi
ID: 17818927
Perfect.

Thanx
0
 
LVL 5

Expert Comment

by:xersoft
ID: 17818938
If you are using .net 2.0 you can use the masked edit textbox and set the mask to "00/00" Does that provide what you are after?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now