![]() |
|
|||||||
| 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 |
|
|||
|
Quote:
Add more logic operators... ![]() @agraham, the challenge for this subroutine isn't over yet. ![]() thanks for helping me... EDIT:thanks for doing this... ![]()
__________________
Rioven Sony Ericsson XPERIA X1i WM6.1 480x800 Display Resolution with QWERTY keyboard |
|
|||
|
This one seems working and applied as subroutine function....yet needs more improvements.
![]() Code:
Sub HHStart_KeyPress (key)
'maxNum, ControlName,key
textboxFilter01("12345","HHStart",key)
End Sub
Code:
Sub textboxFilter01(MaxNum,tb,key) HHshadow=Control(tb).Text 'process only numbers and backspace If (IsNumber(key) = false AND Asc(key) <> 8) Then Control(tb).ignorekey Return End If 'mouse selected character and replace If Control(tb).SelectionLength<>0 AND Asc(key) <> 8 Then s = Control(tb).SelectionStart Control(tb).Text=StrRemove(Control(tb).Text,s,Control(tb).SelectionLength) Control(tb).SelectionStart=s n=StrInsert(Control(tb).Text,Control(tb).selectionstart,key) If (Asc(key) <> 8 AND n>maxNum ) Then Control(tb).Text=HHshadow Control(tb).SelectionStart=s Control(tb).SelectionLength=1 End If End If 'insert input If StrLength(Control(tb).text)<StrLength(maxnum) Then n=StrInsert(Control(tb).Text,Control(tb).selectionstart,key) If (Asc(key) <> 8 AND n>maxNum ) Then Control(tb).ignoreKey End If End If 'limiting input length If (StrLength(Control(tb).text)>=StrLength(maxnum) AND Asc(key) <> 8) Then Control(tb).IgnoreKey Return End If End Sub ![]()
__________________
Rioven Sony Ericsson XPERIA X1i WM6.1 480x800 Display Resolution with QWERTY keyboard |
|
||||
|
Yeah. I realised that last night. There is a fundamental problem in that you don't know and can't find where the insertion point is. So you can deal with selections and normal input appended at the end but cannot predict the result of insertions. The only way round this I can think of is to reset the insertion point to disallow insertion and also disallow leading zeros
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 StrLength(HHstart.text) = 0 AND Asc(Key) = 48 Then
'don't allow leading zeros
HHstart.IgnoreKey
Return
End If
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
HHStart.SelectionStart = StrLength(HHshadow)
HHshadow = HHshadow & key
End If
If IsNumber(key) AND HHshadow > MAXNUM Then
HHstart.IgnoreKey
Return
End If
End Sub
|
|
||||
|
Hello agraham,
I know it is very difficult and you do not have enough weapons to fight. But if you use your ControlEvents and catch TextChanged event you need only to check for the value of the Textbox and if it is out of the limits, restore it to it's previous state or show a warning messagebox. Didn't test it. Am I wrong? |
|
||||
|
Hi dzt
You are right but I was trying to do it only with what is supplied with B4PPC. I was also trying to avoid the warning message because if you do that you may as well keep it very simple, catch LostFocus in B4PPC and show a message box. |
|
||||
|
As dzt suggested here it is using my ControlEvents libary - a bit too easy really!
Code:
Sub Globals
'Declare the global variables here.
MAXNUM = 3456
Dim AGeventsTextSave
End Sub
Sub App_Start
Form1.Show
' AGeventsX is a ControlEvents object
AGeventsX.New1("AGevents")
End Sub
Sub AGeventsX_TextCHanged()
If AGevents.Text > MAXNUM Then
AGevents.Text = AGeventsTextSave
AGevents.SelectionStart = StrLength(AGevents.text)
Else
AGeventsTextSave = AGevents.Text
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 |