Connecting Tech Pros Worldwide Forums | Help | Site Map

ucase

lee123's Avatar
Site Addict
 
Join Date: Feb 2007
Location: United States
Posts: 532
#1: Jan 13 '08
how do you change a certsain field to all caps i have tried this statement but didn't work:

Expand|Select|Wrap|Line Numbers
  1. txtcompanyname.seltext = ucase(txtcompanyname.Seltext)
is this correct or what else do i need to add

ps. i put this in the form load event does that matter?

lee123

Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#2: Jan 13 '08

re: ucase


Quote:

Originally Posted by lee123

Expand|Select|Wrap|Line Numbers
  1. txtcompanyname.seltext = ucase(txtcompanyname.Seltext)

This statement should do the trick.

But note that as with any other statement, it only does its job once, when you execute it. So if it is done in the Form_Load event, it will happen once while the form is being loaded. If there's nothing in the textbox at that time, it won't have any effect.

Hm... on further consideration, I doubt this will ever have any effect. Because you are referring to SelText, which is presumably the selected part of the text. How could you have selected any of the text before the form is even displayed?
lee123's Avatar
Site Addict
 
Join Date: Feb 2007
Location: United States
Posts: 532
#3: Jan 13 '08

re: ucase


hey killer42,

so how do i make it so when i enter in the name it comes out in caps if the caps is not on.

by the way i got this code out of a book as an example

lee123
Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#4: Jan 14 '08

re: ucase


Well, you put this code where you want it to execute. For instance, if you want it to happen every time the user presses a key, you'd put it in the textbox's KeyDown or KeyPress event procedure. However, if you're not careful this can mess up the user by changing their cursor position within the text while they're typing - not nice. Possibly a better point to do it is when the focus leaves the textbox (LostFocus event).

Note that I'm referring to events in VB6. The names and so on may vary slightly in your version. Judging by the use of .SelText I'm guessing this is a later version than mine.

Also, keep in mind whether you want to adjust all of the textbox contents, or just the part which is currently selected. My guess is that the .SelText property refers to the latter. For the entire contents you'd probably want to use either .Text or .Value property.


P.S. It would really help if you fill us in on some background. Such as what version of VB you're using, what you mean by a "field" and so on. I've been assuming you're referring to a textbox control.
lee123's Avatar
Site Addict
 
Join Date: Feb 2007
Location: United States
Posts: 532
#5: Jan 14 '08

re: ucase


Ok im using vb6 and i just wanted to (cap) a textbox named (txtcompanyname)
the (seltext) i got from a book named mastering visual basic 6.0 i guess i was just looking what i could do for this textbox to have enter all caps in this box only.

lee123
lee123's Avatar
Site Addict
 
Join Date: Feb 2007
Location: United States
Posts: 532
#6: Jan 14 '08

re: ucase


oops wrong button any thanks killer42 it works now.

lee123
Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#7: Jan 14 '08

re: ucase


Quote:

Originally Posted by lee123

oops wrong button any thanks killer42 it works now.

Glad to hear you've sorted it out. :)

Oh, and I made a big goof in my earlier post. SelText is a property of textboxes in VB6. I had just forgotten it.
Reply