Link to home
Start Free TrialLog in
Avatar of mscala
mscala

asked on

Limiting number of Characters

I am using VB6.
I would like to limit the number of characters a user inputs, in a text field.

When the user enters free text, but i would like to limit the text field to say 20 characters. How could i do this?
As in when the limit is reached, the cursor must not be able to move any longer.

Thanks

ASKER CERTIFIED SOLUTION
Avatar of setiawan
setiawan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mscala
mscala

ASKER

setiawan

Hi, thanks very much, that works perfectly.
One thing though, when the user enters the text and the characters are up, the cursor returns to the beginning, how would you just keep the cursor at the end or the text message?

Thanks!
Hi mscala,

You can use SelStart property

Private Sub Text1_Change()
    If Len(Text1.Text) > 20 Then
        Text1.Text = Left(Text1.Text, 20)
        Text1.SelStart = Len(Text1.Text)
    End If
End Sub

  danny


Avatar of mscala

ASKER

Answer accepted
Avatar of mscala

ASKER

Perfect!
Thanks very much!
your most welcome :)