By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,578 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,578 IT Pros & Developers. It's quick & easy.

Capitalize First Character?

P: n/a
In VB6, I had some code which 'forced' the first character of a string entered
to be Capital. For example, if a person was entering their name (john doe)...
the code would 'force' --- John Doe.

Here is what I believe is the VB6 code:

Private Sub txbModUser_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txbModUser.TextChanged
KeyAscii = AutoType(Screen.ActiveControl, KeyAscii)
End Sub

Public Function AutoType(ByVal c As Control, ByVal KeyAscii As Integer) As
Integer
' Forces Uppercase for First Character in String
AutoType = KeyAscii
If KeyAscii > 95 And KeyAscii < 123 Then
If c.SelStart = 0 Then
AutoType = AutoType - 32
ElseIf Mid$(c.Text, c.SelStart, 1) < "!" Then
AutoType = AutoType - 32
End If
End If
End Function
Is there a way to do this in VB.net?

Also, how can I toggle the Caps Lock Key? I know it's something to do with
"System.Windows.Forms.Keys.CapsLock". But how to test for it on/off?

Thanks!

Bruce
Jul 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Cor
Hi Mr. B,
Take a look at:
str = StrConv(str, vbProperCase)
Cor
Jul 21 '05 #2

P: n/a
Hi, It's easier than you think, in VB.NET and in VB6:

Dim strName As String = "tom spink"

strName = StrConv(strName, VbStrConv.ProperCase)

MsgBox(strName)

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"Mr. B" <Us**@NoWhere.Com> wrote in message
news:ek********************************@4ax.com...
: In VB6, I had some code which 'forced' the first character of a string
entered
: to be Capital. For example, if a person was entering their name (john
doe)...
: the code would 'force' --- John Doe.
:
: Here is what I believe is the VB6 code:
:
: Private Sub txbModUser_TextChanged(ByVal sender As System.Object, ByVal
e As
: System.EventArgs) Handles txbModUser.TextChanged
: KeyAscii = AutoType(Screen.ActiveControl, KeyAscii)
: End Sub
:
: Public Function AutoType(ByVal c As Control, ByVal KeyAscii As Integer)
As
: Integer
: ' Forces Uppercase for First Character in String
: AutoType = KeyAscii
: If KeyAscii > 95 And KeyAscii < 123 Then
: If c.SelStart = 0 Then
: AutoType = AutoType - 32
: ElseIf Mid$(c.Text, c.SelStart, 1) < "!" Then
: AutoType = AutoType - 32
: End If
: End If
: End Function
:
:
: Is there a way to do this in VB.net?
:
: Also, how can I toggle the Caps Lock Key? I know it's something to do
with
: "System.Windows.Forms.Keys.CapsLock". But how to test for it on/off?
:
: Thanks!
:
: Bruce
Jul 21 '05 #3

P: n/a
Hello,

"Mr. B" <Us**@NoWhere.Com> schrieb:
In VB6, I had some code which 'forced' the first character of a
string entered to be Capital. For example, if a person was entering
their name (john doe)... the code would 'force' --- John Doe. [...] Is there a way to do this in VB.net?
\\\
s = StrConv("john doe", VbStrConv.ProperCase)
///
Also, how can I toggle the Caps Lock Key? I know it's
something to do with "System.Windows.Forms.Keys.
CapsLock". But how to test for it on/off?


Untested:

\\\
MsgBox((Control.ModifierKeys And Keys.CapsLock) = Keys.CapsLock)
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Jul 21 '05 #4

P: n/a
With Deft Fingers, "Cor" <no*@non.com> wrote:
Hi Mr. B,
Take a look at:
str = StrConv(str, vbProperCase)


Yeah! Thanks!

Bruce
Jul 21 '05 #5

P: n/a
With Deft Fingers, "Tom Spink" <th**********@ntlworld.com> wrote:
Hi, It's easier than you think, in VB.NET and in VB6:


Yeah it sure was/is!

Thanks!

Bruce
Jul 21 '05 #6

P: n/a
With Deft Fingers, "Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote:
Is there a way to do this in VB.net?

s = StrConv("john doe", VbStrConv.ProperCase)


Thanks. That seems to be 'the' way.
something to do with "System.Windows.Forms.Keys.
CapsLock". But how to test for it on/off?

Untested:
MsgBox((Control.ModifierKeys And Keys.CapsLock) = Keys.CapsLock)


Well I get "False" in both cases (on/off). I'll play with it a bit.

Thanks.

Bruce
Jul 21 '05 #7

P: n/a
Hello,

"Mr. B" <No*****@address.not> schrieb:
Untested:
MsgBox((Control.ModifierKeys And Keys.CapsLock)

= Keys.CapsLock)

Well I get "False" in both cases (on/off). I'll play with it a bit.


Sorry, that won't work. Forget about that. You will have to use pinvoke
with 'GetAsyncKeyState'.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Jul 21 '05 #8

P: n/a
With Deft Fingers, "Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote:
Sorry, that won't work. Forget about that. You will have to use pinvoke
with 'GetAsyncKeyState'.


Not to worry... with your 'leeetttlle' bit o' code, it resolved the 'need' to
check for Caps Lock (I was going to 'force' lower case input, then capitalize
the first letter). Nada now (:

Thx

Bruce
Jul 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.