• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

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
0
vcharles
Asked:
vcharles
  • 4
  • 2
1 Solution
 
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
 
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now