![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Has anyone figured out a way to filter textbox input? For example, I wish to have the textbox ignore any key press that is not numeric. I tried the IsNumber function in the KeyPress event but that doesn't work.
The first approach I tried was: Sub TextBox1_KeyPress (key) if IsNumeric(key) = False then key = "" End Sub But changing the variable "key" within that subroutine does not do anything to what is displayed in the textbox. To illustrate this, replace the "if" statement above with "key = R". The textbox will still display what you type, not the value "R". My second approach was to chop the right-hand character off of TextBox1.Text but alas, TextBox1.Text is not updated until AFTER the TextBox1.KeyPress(key) subroutine has been completed. The only other events for a textbox are GotFocus and LostFocus, neither of which helps for this problem. The KeyPress event allows me to detect which key was pressed, but does not let me do anything about it. Any ideas? -dlfallen |
|
|||
|
B4PPC community, Hi!
I'm coding a dynamic textbox input and need help (the last item). Any simple or correct solution for these filters? Code:
Sub HHStart_KeyPress (key) 'input only number If IsNumber(key) = false AND Asc(key) <> 8 Then HHstart.IgnoreKey 'mouse selected character and replace If StrLength(HHStart.Text) <=2 AND HHstart.SelectionLength<>0 Then s = HHStart.SelectionStart HHstart.Text=StrRemove(HHstart.Text,s,HHstart.SelectionLength) HHStart.SelectionStart=s End If 'limiting input length If StrLength(HHstart.text)>=2 AND Asc(key) > 31 Then HHstart.IgnoreKey 'limiting input number range ????????? from 0 to 24 only End Sub ![]()
__________________
Rioven Sony Ericsson XPERIA X1i WM6.1 480x800 Display Resolution with QWERTY keyboard |
|
|||
|
Hi agraham, thanks for your help, I could apply you techniques but still need to fix something...
when mouse is placed in between the 2 digits and use backspace, I could enter number that results more than 24, sometimes cannot enter any valid number. or When there is an existing 1 digit, and input number before this digit, I could enter number that results more than 24, sometimes cannot enter any valid number. My problem looks simple, but seems no shortcut solution? ![]() but if you can easily solve the above...will be much appreciated. thanks again.
__________________
Rioven Sony Ericsson XPERIA X1i WM6.1 480x800 Display Resolution with QWERTY keyboard |
|
||||
|
Or maybe a TrackBar?
The logic is more complicated than it seems. So brute force then? Code:
Sub HHStart_KeyPress (key)
'process only numbers and backspace
If (IsNumber(key) = false AND Asc(key) <> 8) Then
HHstart.IgnoreKey
Return
End If
End Sub
Sub HHStart_LostFocus (key)
'process only numbers and backspace
If HHStart.Text <0 OR HHStart.Text > 24 Then
Msgbox("Must be between 0 and 24")
HHStart.Focus
End If
End Sub
|
|
|||
|
Yes Erel, I have thought about that and more often applied on hours, but if I have solution for these kind of filters on textbox, I could think of some other positive applications.
Quote:
difficult for years of not writing code like me, only started again when found Basic4PPC and still refreshing and learning. I could try to do some logic flowcharting then...as it seems I could not do it on the spot anymore.![]() thank you!
__________________
Rioven Sony Ericsson XPERIA X1i WM6.1 480x800 Display Resolution with QWERTY keyboard |
|
||||
|
Quote:
Code:
Sub HHStart_KeyPress (key)
' I know this takes time but this is slow user input processing and avoids global clutter
MAXNUM = 3456
HHshadow = HHstart.text
If (IsNumber(key) = false AND Asc(key) <> 8) Then
'process only numbers, Asc("0")=48, AsSc("1")= 50 etc. and backspace = 8
HHstart.IgnoreKey
Return
Else If HHstart.SelectionLength <> 0 Then
' part of string selected
ss = HHStart.SelectionStart
sl = HHStart.SelectionLength
hl = StrLength(HHstart.text)
first = SubString(HHshadow,0,ss)
last = SubString(HHshadow,ss+sl,hl-sl)
HHshadow = first & key & last
Else
' no selection so process normally and check limit
HHshadow = HHshadow & key
End If
If IsNumber(key) AND HHshadow > MAXNUM Then
HHstart.IgnoreKey
Return
End If
End Sub
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SIP Input | leestevens | Questions & Help Needed | 2 | 08-01-2008 04:00 PM |
| SOund Input? | PKinz | Basic4ppc Wishlist | 1 | 12-12-2007 03:51 PM |
| How to limit a textbox input strlength | taximania | Questions & Help Needed | 5 | 08-27-2007 06:08 PM |
| Input Panel | Erel | Code Samples & Tips | 17 | 07-04-2007 04:29 AM |
| Sound/Mic input | Bill Todd | Questions & Help Needed | 2 | 06-22-2007 12:29 PM |