![]() |
|
|||||||
| 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 |
|
|||
|
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 |
|
||||
|
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 |
|
||||
|
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 |
|
|||
|
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 |
![]() |
| 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 |
| 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 |