473,378 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Limit users input to textbox

Good Day to you all,

I have an application where i want to limit a user's input to the textbox. What i want is that they wont exceed the textbox width and when that textbox is full it will automatically go to the next textbox. Im using Visual Basic 6.0.

Thanks for the help.
Nov 27 '14 #1
8 2572
Luuk
1,047 Expert 1GB
The property for setting the MaxLength is called MaxLength
(http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspx)

something like the code below might get you from TextBox1 to TextBox2
Expand|Select|Wrap|Line Numbers
  1.     Private Sub TextBox1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
  2.         If TextBox1.Text.Length  = 4 Then
  3.             TextBox2.Focus()
  4.         End If
  5.     End Sub
  6.  
But there ARE better ways ;)
Nov 27 '14 #2
Luuk thanks for the reply.
but is there other ways other than MaxLength? i dont want to limit it by characters. i want to limit the input just within the textbox's width, if its possible.
Nov 28 '14 #3
Luuk
1,047 Expert 1GB
How wide is a character?
An 'i' is less wide than a 'w'....

So, how much characters do fit in a textbox's width?

MaxLength is just to make sure you cannot enter more characters than given in that property.
Nov 28 '14 #4
twinnyfo
3,653 Expert Mod 2GB
All,

There are ways to do this, but it is very involved, and includes creating a separate class to limit the size of the input for a text box. The code I have is 200 lines long. Not sure that is the simplicity you are looking for.....
Dec 1 '14 #5
Luuk
1,047 Expert 1GB
The code i gave will work too, if you also use the MaxLength

If you do not use MaxLength, it will be possible to paste a too long text.
Dec 1 '14 #6
Frinavale
9,735 Expert Mod 8TB
Using the TextBox1.Text.Length to determine when to move to the next TextBox is not correct.

You need to check if the position of the cursor in the TextBox to see if it is at the end and only move to the next TextBox if the cursor is at the end of the allotted space.

Likewise, you will probably have to do the same thing for the backspace key to move back a TextBox upon having the cursor in the first position of the TextBox...

Twinnyfo's reply is correct: there is no real simple solution.
Dec 1 '14 #7
Luuk
1,047 Expert 1GB
How does that relate to this article:
How to: Position the Cursor at the End of Text in a TextBox Control

?
Dec 1 '14 #8
twinnyfo
3,653 Expert Mod 2GB
Luuk, et al,

We must make sure we differentiate betwixt "Text Box Width"--which is the specific question of the OP, and "Text Length"--which is always based on the number of characters.

Text Box Width is a physical measurement, which may differ based on OS Display settings. If we create a form that has a text box on it that is one inch wide (1440 twips), then that is a physical limitation of the text box. It is possible to overflow the size of a text box, at which point the text will not display properly.

Text Length is always an integer and is a count of the number of characters. I know you know this and fully understand the difference between these two, so I am not saying this to insult anyone's intelligence or competence....

It is possible to display a differing number of characters within the same text box. One could reduce the font size, and more characters could fit. One could use all skinny letters (e.g. "iiiiiiiiii" takes up less room than "wwwwwwwwww" with most font styles). Limiting the text box to the length of string to 10 characters will limit the amount of data that may be entered, but will not take into account either the size of the text box (a physical measurement) nor the size of the characters within the font set.

I do have some code which will calculate all this stuff (via another web site (sorry, Mods), but again--it is 100's of lines of code. I got mine to work for an experiment I was doing a while back, but have limited use for it right now.

If anyone is interested in this, I am glad to share--just not sure I remember all the tweaks needed to get it to work properly.
Dec 2 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Astra | last post by:
Hi All Could somebody confirm if and how I can change the TYPE of a textbox from PASSWORD to TEXT depending on whether a user checks a checkbox. In essence I have a login and password form and...
2
by: SAN CAZIANO | last post by:
how can I have on the right of an input field the number of the char that we can put on it (when it's length is changed this number must changed itself: perhaps onkeypress event)???
2
by: Parintas Themis STE Kardias | last post by:
I have a textbox, and i wand to put a limit (for example only 8 characters) and if i entry characters not longer of 8 then add spaces for the rest of textbox characters
1
by: Parintas Themis STE Kardias | last post by:
I have a textbox and sent data to this text with the command paste, how can i make the text box to accept only the first 8 characters only.
6
by: Maziar Aflatoun | last post by:
Hi, I have a little application that reads a text file line-by-line and processes each line depending on the CVS values. Now I want to change my program to capture this from a textbox. How do...
1
by: cw | last post by:
Hi all, Is anyone have an idea that limit message length input by user into textbox. I'hv tried the maxlength property by setting it to 150, but it seems like not working.., regards
1
by: craigkenisston | last post by:
I'm creating a form with asp.net. I have my inputs like this : <label for="USER_COMPANY">Company Name:</label> <asp:textbox id="USER_COMPANY" runat="server" cssclass="inputBox"...
1
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to validate an email address entered into an input textbox. Does anyone have any code for this? -- Michael Bragg, President...
9
by: xiaowei | last post by:
Hi all, I am really new to the use of Access, or rather, the work dealing with codes and applications. Now I am working with this huge Access 2003 database. How can I possibly create some...
2
by: perhapscwk | last post by:
My code below, I can add and remove textbox, however, it can add/remove the last one only. How I can add a input textbox between field? thanks. my html file <script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.