Help with controlling input to textbox using vb.net

Hi,

How do you force users to enter data after 4 spaces from the left of the textbox using vb.net?

Victor
vcharlesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
You don't.

You add them yourself after the user gets out of the TextBox.

Users do not like to be "forced" into something, and no matter what you try to do, you might forget something. You can be sure that they will find a way around it.

Some programmers will have the reflex of catching the KeyPress and prevent the users from typing anything else but spaces until the TextBox is at least 4 characters, so they have to first type the 4 spaces. Users will then be able to type something like "    abcd", come back to delete the spaces. Since there are 4 characters in the TextBox now, the method stops working.

You correct that problem by always check if there are at least 4 spaces. They will come out with Copy/Paste, that does not go through the KeyPress. You correct that, they will find something else.

So the easiest way is to do it yourself, in one of the events that are triggered when they get out of the TextBox, such as Validating.

TextBox1.Text = "    " & TextBox1.Text.TrimStart

The TrimStart removes the spaces that the user might have written himself, making sure that you end up with 4 spaces, not 5,6,7 or 8.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike EghtebasDatabase and Application DeveloperCommented:
re:> after 4 spaces

What are typical entries in these first 4 spaces?

How they are entered in this text box.

If the initial entry is:
txtValue --> [ABCD             ]
After user enters 123, for example, the new text value will become:  txtValue --> [ABCD123          ]

What is the validation rule for the entry like 123 so that it can be handled at the same time you are forcing user to enter a value after 4 spaces.

What you want has to be handled on exit, for example, under validation rule. Validation will force user to enter the desired value in this text box.

Mike
0
vcharlesAuthor Commented:
Hi,

I would like the leave the 4 spaces empty, will then concatenate values from another text box in that space (i.e +055) when i load the form again.

Thanks,

Victor
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

vcharlesAuthor Commented:
Hi again,

Is possible to move the text they type by 4  spaces to the right prior to saving the data to an xml file? With such approach they would not encounter  any testri tions.
0
Jacques Bourgeois (James Burger)PresidentCommented:
If you are going to concatenate something at the beginning of the string, do not care about recording the 4 spaces. Simply add them when you will be ready:

Simply record what the user typed, and when ready, concatenate:

"055" & "    " & TextBox1.Text
0
vcharlesAuthor Commented:
Got it.
Thanks.
Victor
0
vcharlesAuthor Commented:
Thank You.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.