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 limit number of digit to enter


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-11-2008, 05:57 PM
Newbie
 
Join Date: Feb 2008
Location: Germany
Posts: 9
Default TextBox limit number of digit to enter

Hello,

does somebody know to limit in a TextBox possible digits
e.g.

Form1 - TextBox1

Sub TextBox1_KeyPress (key)
If StrLength(textbox1.Text)>3 Then
key=""
End If
End Sub

I want to limit the Textbox to max. 3 digits, is this possible.

Best Regards

Michael
Reply With Quote
  #2 (permalink)  
Old 08-11-2008, 07:09 PM
taximania's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 231
Awards Showcase
Beta Tester 
Total Awards: 1
Default

This was not done by me.
I think it's agraham who wrote this code.
I think the number 2 is correct for your needs.

Code:
Sub TextBox1_KeyPress (key)
    If StrLength( textbox1.Text) >=2 Then	
        If Asc(key)>31 Then
            ss = Textbox1.SelectionStart
            Textbox1.Text= SubString(Textbox1.Text,0,2)
            Textbox1.SelectionStart = ss
        End If
    End If
End Sub
__________________
Endemol
Waste of space

O2 XDA Artemis Touch Flo 4.02 Full Cube Rom WM6.1

http://www.taximania.net
Reply With Quote
  #3 (permalink)  
Old 08-11-2008, 08:43 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 638
Default

If you want to do it a more elegant way, just have a look at filippos fgcontrols library.

The fgTextBox provides a MaxLenght and a OnlyNumber property.


specci48
Reply With Quote
  #4 (permalink)  
Old 08-12-2008, 09:34 PM
Newbie
 
Join Date: Feb 2008
Location: Germany
Posts: 9
Default

Thanks for all the idea,
my final solution is now

On Form1 are 2 TextBox Controls:

Sub App_Start
AddEvent("TextBox1",KeyPress,"TextBox_maxC5_KeyPre ss")
AddEvent("TextBox2",KeyPress,"TextBox_maxC5_KeyPre ss")
Form1.Show
End Sub


Sub TextBox_maxC5_KeyPress (key)
If StrLength(Control(Sender))=5 AND _
( IsLetter(key) OR IsNumber(key) ) Then
Control(Sender).IgnoreKey
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
scrolling image with limit europe Questions & Help Needed 1 11-07-2008 05:54 PM
Listbox and enter key tsteward Questions & Help Needed 2 10-14-2008 07:30 AM
Running programs - is there a depth limit. Also window waking LineCutter Questions & Help Needed 0 01-28-2008 12:41 AM
How to limit a textbox input strlength taximania Questions & Help Needed 5 08-27-2007 06:08 PM
table Dezimalseparator saveCSV 64k limit BerndB Questions & Help Needed 0 05-02-2007 04:58 PM


All times are GMT. The time now is 04:41 PM.


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