Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

DateTiem and Textbox

Posted on 2006-05-03
3
Medium Priority
?
224 Views
Last Modified: 2010-04-23
Hi

VB .Net windows project.

I have several textboxes that containes a date (In Denmark dd-mm-yyyy).
To help the user putting in "-" automatic - I have made the following code: and it workes ok ...and still not.
Everytime the code puts in "-" then the Cursor returns to the start of the textbox! How can I prevent that?

Regards Steen

    Private Sub TextBox18_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox18.TextChanged
        If Len(Me.TextBox18.Text) = 2 Then Me.TextBox18.Text = Me.TextBox18.Text & "-"
        If Len(Me.TextBox18.Text) = 5 Then Me.TextBox18.Text = Me.TextBox18.Text & "-"
    End Sub
0
Comment
Question by:steensommer
  • 2
3 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 16601663
Hi steensommer;

This will do it for you.

    Private Sub TextBox18_TextChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles TextBox18.TextChanged

        If Len(Me.TextBox18.Text) = 2 Then
            Me.TextBox18.Text = Me.TextBox18.Text & "-"
            Me.TextBox18.Select(TextBox18.Text.Length, 1)
        End If

        If Len(Me.TextBox18.Text) = 5 Then
            Me.TextBox18.Text = Me.TextBox18.Text & "-"
            Me.TextBox18.Select(TextBox18.Text.Length, 1)
        End If

    End Sub

Fernando
0
 
LVL 1

Author Comment

by:steensommer
ID: 16601722
This works fine - Thank you!!!
Regards Steen
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 16601783
Glad I was able to help.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

572 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