[Gambas-user] How to make Textbox only accept alphabetic and numbers characters

Tobias Boege tobs at taboege.de
Mon May 10 13:39:11 CEST 2021


On Mon, 10 May 2021, Bruce wrote:
> On 10/5/21 8:54 pm, Hasan Merkit wrote:
> > How i can make a textbox only accept alphabetic characters?
> > 
> > 
> > In VB.Net, i do this:
> > 
> > 
> > Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) _Handles txtName.KeyPress
> > 
> >      If Not (Asc(e.KeyChar) = 8) Then
> > 
> >          Dim allowedChars As String = "abcdefghijklmnopqrstuvwxyz0123456789"
> > 
> >          If Not allowedChars.Contains(e.KeyChar.ToString.ToLower) Then
> > 
> >              e.KeyChar = ChrW(0)
> > 
> >              e.Handled = True
> > 
> >          End If
> > 
> >      End If
> > 
> > 
> > 
> > End Su
> > 
> 
> Well that may work in VB.net but not here. Why would you think it would.
> Gambas has an excellent help system, but as I have sais many times before,
> you must read every word, every word and the every word. Try reading the
> help for the TextBox control, in particular the events.
> 
> Sheesh! How many times do I have to reply to this same question.
> 
> You probably want TextBox.Change.
> 

More specifically, Hasan, you want to apply the "read every word" advice
to the help page for the TextBox KeyPress event:

  http://gambaswiki.org/wiki/comp/gb.qt4/control/.keypress

Regards,
Tobias

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list