Capitalize First Character?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mr. B

    Capitalize First Character?

    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_Text Changed(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles txbModUser.Text Changed
    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.Cap sLock". But how to test for it on/off?

    Thanks!

    Bruce
  • Cor

    #2
    Re: Capitalize First Character?

    Hi Mr. B,
    Take a look at:
    str = StrConv(str, vbProperCase)
    Cor


    Comment

    • Tom Spink

      #3
      Re: Capitalize First Character?

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

      Dim strName As String = "tom spink"

      strName = StrConv(strName , VbStrConv.Prope rCase)

      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" <User@NoWhere.C om> wrote in message
      news:ek4tmv07cb ptv4ks1khmlq4bv eene0gvr8@4ax.c om...
      : 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_Text Changed(ByVal sender As System.Object, ByVal
      e As
      : System.EventArg s) Handles txbModUser.Text Changed
      : 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.Cap sLock". But how to test for it on/off?
      :
      : Thanks!
      :
      : Bruce


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Capitalize First Character?

        Hello,

        "Mr. B" <User@NoWhere.C om> schrieb:[color=blue]
        > 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.[/color]
        [...][color=blue]
        > Is there a way to do this in VB.net?[/color]

        \\\
        s = StrConv("john doe", VbStrConv.Prope rCase)
        ///
        [color=blue]
        > 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?[/color]

        Untested:

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

        --
        Herfried K. Wagner
        MVP · VB Classic, VB.NET
        Die Website von H. Wagner zu .NET, Visual Basic .NET, Classic Visual Basic, Webentwicklung und mehr.



        Comment

        • Mr. B

          #5
          Re: Capitalize First Character?

          With Deft Fingers, "Cor" <non@non.com> wrote:
          [color=blue]
          >Hi Mr. B,
          >Take a look at:
          >str = StrConv(str, vbProperCase)[/color]

          Yeah! Thanks!

          Bruce

          Comment

          • Mr. B

            #6
            Re: Capitalize First Character?

            With Deft Fingers, "Tom Spink" <thomas.spink@n tlworld.com> wrote:
            [color=blue]
            >Hi, It's easier than you think, in VB.NET and in VB6:[/color]

            Yeah it sure was/is!

            Thanks!

            Bruce

            Comment

            • Mr. B

              #7
              Re: Capitalize First Character?

              With Deft Fingers, "Herfried K. Wagner [MVP]" <hirf.nosp@m.ac tivevb.de> wrote:
              [color=blue][color=green]
              >> Is there a way to do this in VB.net?[/color]
              >s = StrConv("john doe", VbStrConv.Prope rCase)[/color]

              Thanks. That seems to be 'the' way.
              [color=blue][color=green]
              >> something to do with "System.Windows .Forms.Keys.
              >> CapsLock". But how to test for it on/off?[/color]
              >Untested:
              >MsgBox((Contro l.ModifierKeys And Keys.CapsLock) = Keys.CapsLock)[/color]

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

              Thanks.

              Bruce

              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: Capitalize First Character?

                Hello,

                "Mr. B" <NotHere@addres s.not> schrieb:[color=blue][color=green]
                > >Untested:
                > >MsgBox((Contro l.ModifierKeys And Keys.CapsLock)[/color]
                > = Keys.CapsLock)
                >
                > Well I get "False" in both cases (on/off). I'll play with it a bit.[/color]

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

                --
                Herfried K. Wagner
                MVP · VB Classic, VB.NET
                Die Website von H. Wagner zu .NET, Visual Basic .NET, Classic Visual Basic, Webentwicklung und mehr.



                Comment

                • Mr. B

                  #9
                  Re: Capitalize First Character?

                  With Deft Fingers, "Herfried K. Wagner [MVP]" <hirf.nosp@m.ac tivevb.de> wrote:
                  [color=blue]
                  >Sorry, that won't work. Forget about that. You will have to use pinvoke
                  >with 'GetAsyncKeySta te'.[/color]

                  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

                  Comment

                  Working...