Jump to content

how can i keep the spaces at end of a textbox in vba?


mas_oyama

Recommended Posts

when i exit a textbox, in vba, it automatically remove the spaces at the end of a textbox... for example, if i type "Thats stupid "(without the quotes...), as soon as i exit the textbox, it is converted to "Thats stupid" (without quotes... duh... and without the spaces i typed). is there a way to keep those spaces? i'm developping a utility to rename files in batch, and if, for example, i want to replace all the spaces by underlines, i want to type " "(without quotes) in txtContaining, and "_"(again, without quotes...) in txtReplaceBy, so when i hit btnProcess, every file in the specified directory will be renamed, by replacing spaces by underline. the whole thing is done, i can replaces "a" for "b", or anything like that, but i can not replace spaces by something, or something by spaces, cause the stupid ****ers at microsoft decided that i cant end a text box by " "...

Link to comment
Share on other sites

i found a way, but its damn ugly! i had to write these 3 subs: (i know the name of the txt box doens match what i said earlier, i'm in a fake, testing form.

Private Sub txtPath_Enter()	VarString= ""	txtPath = ""End SubPrivate Sub txtPath_KeyPress(KeyAscii As Integer)	On Error Resume Next		Select Case KeyAscii		Case 8 'Bacspace			VarString= ""			txtPath = ""			'VarString= Left(VarString, Len(VarString) - 1)		Case 13 'Enter		Case Else			VarString= VarString& "" & Chr(KeyAscii)	End SelectEnd SubPrivate Sub txtPath_Exit(Cancel As Integer)	Call MsgBox("""" + VarString+ """")End Sub

VarStringis a global string variable. thats not really pretty: as soon as i enter the txtbox, i clear both the txtbox and the variable, to be sure the user start over... you'll understand why if you test. the same goes if i press backspace : if your not at end of the textbox, i cant posibly know where you are(so where to delete a character from the string). anyway, that barely works... if you type text somewhere else than at the end(if you moved with the arrows), the text will still be appended at the end of the variable... lol. thats not right!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...