Results 1 to 7 of 7

Thread: how to get the length of entered data in a text box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    Pakistan
    Posts
    262

    how to get the length of entered data in a text box

    Hi,

    Can any one please guide me that hw to take the length of the entered data in a text box so that its length can be checked?Actually I have restricted a text box data length by using its property of Max length,the next step is to set focus to the next text box..so please guide me.

    Regards,

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: how to get the length of entered data in a text box

    Use the Len() function
    VB Code:
    1. If Len(Text1.Text) = 10 Then 'change the 10 to suit the length of yours
    2.  Text2.SetFocus
    3. End If

    casey.

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: how to get the length of entered data in a text box

    VB Code:
    1. Private Sub Command1_Click()
    2.  'Displays the length of the text entered in the text box
    3.  'Len <--- To get the length
    4.  'Trim <-- Trim the text box string
    5.  MsgBox Len(Trim(Text1.Text))
    6.  'moves the control to the Text box called Text2
    7.  Text2.SetFocus
    8. End Sub

  4. #4
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: how to get the length of entered data in a text box

    VB Code:
    1. If Len(text1.text) = 10 then  ''Assuming Max property is set to 10
    2. text2.setfocus    'if textbox1 contains 10 characters set the focus to text2
    3. Else
    4. Msgbox "Please Enter a max of 10 Characters"
    5. End if
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: how to get the length of entered data in a text box

    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.     'This will move the focus if the lenght of the text is equal to 10
    3.     If Len(Text1.Text) = 10 Then
    4.         Text2.SetFocus
    5.     End If
    6. End Sub

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: how to get the length of entered data in a text box

    Have we given the sollution?

  7. #7
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: how to get the length of entered data in a text box

    VB Code:
    1. Private Sub Text1_Change()
    2.     If [B]Len(Text1.Text)=Text1.MaxLength[/B] Then
    3.         Text2.SetFocus
    4.     Else
    5.         MsgBox "Enter more..."
    6.     End If
    7. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width