Capitalize First Character?

  • Thread starter Thread starter Mr. B
  • Start date Start date
M

Mr. B

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
 
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"


: 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
 
Hello,

Mr. B said:
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 said:
s = StrConv("john doe", VbStrConv.ProperCase)

Thanks. That seems to be 'the' way.
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
 
Hello,

Mr. B said:
= 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 said:
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
 
Back
Top