K kavka Member Licensed User Mar 12, 2008 #1 Hello! Is it possible to define a textbox, that it will not accept fonts and will accept only numbers? Any ideas? Thx, Kavka
Hello! Is it possible to define a textbox, that it will not accept fonts and will accept only numbers? Any ideas? Thx, Kavka
H Hennell Member Licensed User Longtime User Mar 12, 2008 #2 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.
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.
agraham Expert Licensed User Longtime User Mar 12, 2008 #3 Right idea but better coded as B4X: Sub TextBox1_KeyPress (key) If (Asc(key) < 48 OR Asc(key) > 59) AND Asc(key) <> 8 Then ' allow 0 to 9 and backspace keys textbox1.IgnoreKey End If End Sub
Right idea but better coded as B4X: Sub TextBox1_KeyPress (key) If (Asc(key) < 48 OR Asc(key) > 59) AND Asc(key) <> 8 Then ' allow 0 to 9 and backspace keys textbox1.IgnoreKey End If End Sub
H Hennell Member Licensed User Longtime User Mar 12, 2008 #4 Huh - I was closer then I thought I'd be. Although forgetting backspace was a daft oversight...
specci48 Well-Known Member Licensed User Longtime User Mar 12, 2008 #5 Hi Hennell, have a look into the italian forum where Filippo provided his fgMaskedEdit.dll: http://www.b4x.com/forum/showthread.php?t=1710 With this dll you can do excatly what you want! EDIT: Filippo provided even another library (fgControls.dll) containing the same an some more features: http://www.b4x.com/forum/showthread.php?t=1238 Cheers specci48 Last edited: Mar 12, 2008
Hi Hennell, have a look into the italian forum where Filippo provided his fgMaskedEdit.dll: http://www.b4x.com/forum/showthread.php?t=1710 With this dll you can do excatly what you want! EDIT: Filippo provided even another library (fgControls.dll) containing the same an some more features: http://www.b4x.com/forum/showthread.php?t=1238 Cheers specci48
Erel B4X founder Staff member Licensed User Longtime User Mar 13, 2008 #6 Small modification: B4X: Sub TextBox1_KeyPress (key) If Not(IsDigit(key)) AND Asc(key) <> 8 Then ' allow 0 to 9 and backspace keys textbox1.IgnoreKey End If End Sub
Small modification: B4X: Sub TextBox1_KeyPress (key) If Not(IsDigit(key)) AND Asc(key) <> 8 Then ' allow 0 to 9 and backspace keys textbox1.IgnoreKey End If End Sub
alfcen Well-Known Member Licensed User Longtime User Mar 13, 2008 #7 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.
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.
D dennishea Active Member Licensed User Mar 15, 2008 #8 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.
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.
K kavka Member Licensed User Mar 17, 2008 #9 Hello! Erel, used your code with small modification you made and works great! Thx, Kavka