Results 1 to 8 of 8

Thread: change to UPPERCASE

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    South-Africa
    Posts
    46

    Post

    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.

  2. #2
    Addicted Member
    Join Date
    Jan 2000
    Location
    Peterborough, Cambs, England
    Posts
    176

    Post

    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)

  3. #3
    Member
    Join Date
    Jan 1999
    Location
    Longmont,CO
    Posts
    53

    Post

    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.


  4. #4
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    Small mistake in mcleran's code:

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(chr(KeyAscii)))

    End Sub


  5. #5
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    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]



  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    South-Africa
    Posts
    46

    Post

    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.

  7. #7
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    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]



  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    South-Africa
    Posts
    46

    Post

    Thanks for all your help - I seemed to work it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width