|
-
Feb 2nd, 2000, 10:20 PM
#1
Thread Starter
Member
What is the best way to change(keep) every string on your form in uppercase.I don't want to allow lowercase in my input boxes.
Any help will bw appreciated.
Thanks.
-
Feb 2nd, 2000, 10:27 PM
#2
Addicted Member
Try the UCase funtion.
Use the keydown event on your text box and put something like this in to it.
txtText.text = UCase(txtText.text)
-
Feb 2nd, 2000, 10:28 PM
#3
Member
Private Sub Text1_KeyPress(KeyAscii As Integer)
Text1.Text = UCase(chr(KeyAscii))
End Sub
this way, each character is converted to upper case as it's entered.
-
Feb 2nd, 2000, 11:00 PM
#4
Member
Small mistake in mcleran's code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(chr(KeyAscii)))
End Sub
-
Feb 3rd, 2000, 12:18 PM
#5
Frenzied Member
I use a slightly more complicated method - this allows for users who copy and paste stuff into input boxes (and, yes, quite a few do).
Include this sub in a module;
Sub FormatTextbox(ThisTextBox As TextBox, ThisFormat As Integer)
Dim OldSelStart As Integer
OldSelStart = ThisTextBox.SelStart
ThisTextBox.Text = StrConv(ThisTextBox.Text, ThisFormat)
ThisTextBox.SelStart = OldSelStart
End Sub
In your TextBox1.Change event put;
FormatTextBox TextBox1, vbUpperCase
Now the box will be formatted UPPERCASE at all times, whether it is changed in code, by a user, by a copy/paste, by keypresses, by a database etc etc etc...
You can use vbLowerCase, vbProperCase etc as well if you like.
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
-
Feb 3rd, 2000, 02:42 PM
#6
Thread Starter
Member
Ok That work quite well.
But I have another question?
I don't want to put this code after every keypress event of a textbox on every form.(That is about 60 textboxes on 6 forms).
Is there a way I can code my program with a few lines that will change every string to uppercase using a public sub or function.(form gotfocus or load etc.)
Thanks.
-
Feb 3rd, 2000, 06:19 PM
#7
Frenzied Member
Although I've only used them once you can achieve many wonderful things with the WithEvents function - see this tip for more information;;
http://www.vb-world.net/controls/tip133.html
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
-
Feb 3rd, 2000, 07:49 PM
#8
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|