Textbox

kavka

Member
Licensed User
Hello!

Is it possible to define a textbox, that it will not accept fonts and will accept only numbers? Any ideas?

Thx, Kavka
 

Hennell

Member
Licensed User
Longtime User
Doubt this is the best way but:

B4X:
Sub TextBox1_KeyPress (key)
   For i = 48 To 57
    If key = Chr(i) Then Return
   Next
textbox1.IgnoreKey
   
End Sub

would make a text box only accept numbers.
 

Hennell

Member
Licensed User
Longtime User
Huh - I was closer then I thought I'd be. Although forgetting backspace was a daft oversight...
 

alfcen

Well-Known Member
Licensed User
Longtime User
Splitting hairs, for decimal numbers in both English (.) and Continental (,)notations as well as allowing for negative numbers:

B4X:
If (Asc(key) < 44 OR Asc(key) > 59) AND Asc(key) <> 8 Then txtZT.IgnoreKey

The included slash, Chr(48), is a compromise for a shorter line of code.
 

dennishea

Active Member
Licensed User
Their are many ways to skin a kitty but team work makes for the most effiecent way. :sign0188:

p.s. I think that this is a ten star forum.
 

kavka

Member
Licensed User
Hello!

Erel, used your code with small modification you made and works great!

Thx, Kavka
 
Top