Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get rid of Automatic space in textbox 2

Status
Not open for further replies.

AuctionLamb

Programmer
Feb 16, 2005
65
ZA
Hi guys!!

Need some help over here.......I am using VB 6.

I have a textbox, and on that textbox I do a validation(must have 8 digits). When I type in for example "12345678" it does not save because it is longer than 8 digits. Then I have found that when I type in something it adds a space at the end automatically "12345678 " so the system see it as 9 characters.

Is there something in the properties menu that I have to set to take it out or not putting it in?

THANKS!!
 
Don't know about the properties you have set but you could validate against the input of the texbox after using the Trim() function to remove leading and trailing spaces?

Hope this helps

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
No.....it is when I actually type in the textbox that the space is getting created
 
Thanks, I understood that from your OP.

Does this happen when you type anything in the textbox??

This might be a silly question but are you aren't using a barcode scanner for the input are you???

Cheers

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
No, the admin people are typing it in. I had a look at the other textbox next to it and it is not doing it. The properties are the same.
 
Out of interest what happens if you set the Max Length of the textbox to 8?

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
That is a some sort of work around but still....when I type in only 1 digit and press the right arrow key it shows the space.
 
OK, if you can type all eight digits in while the max length of the box is 8 then the space isn't there to start with, that's for certain.

Do you have any code on the Key event(KeyPress, KeyUp etc.) that might be causing this behaviour?

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Will add the maxlenth in the properties. Nope I have no code in the Key Events.
 
With the Max Length set as 8 can you type in all 8 digits?

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
When you type in the digits in the textbox with the MAXLENTH properties you only get "1234567 " because it counts the space as a character.
 
On the form_load event could you try setting the .Text property of the box to be .Text = "" and see if that makes a difference?

Or in the properties of the box make sure the Text property isn't set as a space (using the arrow keys as you did in a earlier response)?

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
I see that the textbox has a space by default in at the beginning but in the TEXT properties it is fine.
 
So if you set it to "" on form_load that would work?? Or not??

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
What happens if you use something like this:
Code:
Private Sub Text1_GotFocus()
Text1.Text = Trim(Text1.Text)
End Sub
?

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
I'd put some logging in the change event of the textbox

Code:
Private Text1_Change()
debug.print "'";text1.text;"' ";len(text1.text)
end sub

and see what happens




Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Matt - Good idea. Hopefully that should help us get this sorted. [smile]

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
So, somewhere in your code the box is populated with a space...

Could you put a break in the code provided by Matt and see when it occurs?

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top