Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


TextBox Input Filter?


Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 10-09-2007, 07:49 PM
dzt's Avatar
dzt dzt is offline
Basic4ppc Veteran
 
Join Date: May 2007
Location: Greece
Posts: 353
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by agraham
I just love a challenge! Try to break this one
Easy!


1. Type 0000 and at the beginning type any number
2. Paste anything Shift-Insert (desktop only, OK doesn't counts)
3. Type 555 and at the beginning try to type any number

__________________
Dimitris Zacharakis
http://www.terracom.gr
Reply With Quote
  #12 (permalink)  
Old 10-10-2007, 02:37 AM
Senior Member
 
Join Date: May 2007
Posts: 130
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by dzt View Post
Easy!


1. Type 0000 and at the beginning type any number
2. Paste anything Shift-Insert (desktop only, OK doesn't counts)
3. Type 555 and at the beginning try to type any number

Not yet foolproof...
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
Reply With Quote
  #13 (permalink)  
Old 10-10-2007, 07:25 AM
Senior Member
 
Join Date: May 2007
Posts: 130
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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
feedbacks are welcome
__________________
Rioven

Sony Ericsson XPERIA X1i WM6.1
480x800 Display Resolution
with QWERTY keyboard
Reply With Quote
  #14 (permalink)  
Old 10-10-2007, 10:03 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,690
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by dzt View Post
Easy!
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
Reply With Quote
  #15 (permalink)  
Old 10-10-2007, 10:29 AM
dzt's Avatar
dzt dzt is offline
Basic4ppc Veteran
 
Join Date: May 2007
Location: Greece
Posts: 353
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

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?
__________________
Dimitris Zacharakis
http://www.terracom.gr
Reply With Quote
  #16 (permalink)  
Old 10-10-2007, 10:52 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,690
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

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.
Reply With Quote
  #17 (permalink)  
Old 10-10-2007, 07:08 PM
dzt's Avatar
dzt dzt is offline
Basic4ppc Veteran
 
Join Date: May 2007
Location: Greece
Posts: 353
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Hi again,

There are significant advantages for TextChanged against LostFocus and KeyPress events.

It is by far the most elegant solution.
__________________
Dimitris Zacharakis
http://www.terracom.gr
Reply With Quote
  #18 (permalink)  
Old 10-10-2007, 07:15 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,690
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Hi dzt

I think you misunderstood. I'm not disagreeing at all - it is the most elegant. I just wanted to see how far I could go "as standard" which is what most people would be comfortable with.
Reply With Quote
  #19 (permalink)  
Old 10-10-2007, 07:50 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,690
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

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
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 06:06 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0