Results 1 to 18 of 18

Thread: [Resolved]How to use To.Upper Procedure?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    60

    Resolved [Resolved]How to use To.Upper Procedure?

    Hello,

    I'm working on a project where an application requires to show 50 US state names.

    When User enters the abriviation in the text box, I want it to convert into Upper case. I made an attempt and coded like this:

    strAbriviation = strAbriviation.ToUpper(txtAbriviation.Text)

    but that didn't work !! it gives me that blue swigly line

    How do I fix this?

    Code:
    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
            Dim strAbriviation As String
    
    
    
            strAbriviation = Convert.ToString(Me.txtAbriviation.Text)
            strAbriviation = strAbriviation.ToUpper(txtAbriviation.Text)
    
    
            Select Case Me.txtAbriviation.Text
                Case "AL"
                    Me.lblResult.Text = "Alabama"
                Case "AK"
                    Me.lblResult.Text = "Alaska"
                Case "AZ"
                    Me.lblResult.Text = "Arizona"
                Case "AR"
                    Me.lblResult.Text = "Arkansas"
                Case "CA"
                    Me.lblResult.Text = "California"
                Case "CO"
                    Me.lblResult.Text = "Colorado"
                Case "CT"
                    Me.lblResult.Text = "Conneticut"
                Case "DE"
                    Me.lblResult.Text = "Delaware"
                Case "FL"
                    Me.lblResult.Text = "Florida"
                Case "GA"
                    Me.lblResult.Text = "Georgia"
                Case "HI"
                    Me.lblResult.Text = "Hawaii"
                Case "ID"
                    Me.lblResult.Text = "Idaho"
                Case "IL"
                    Me.lblResult.Text = "Illinois"
                Case "IN"
                    Me.lblResult.Text = "Indiana"
                Case "IA"
                    Me.lblResult.Text = "Iowa"
                Case "KS"
                    Me.lblResult.Text = "Kansas"
                Case "KY"
                    Me.lblResult.Text = "Kentucky"
                Case "LA"
                    Me.lblResult.Text = "Louisiana"
                Case "ME"
                    Me.lblResult.Text = "Maine"
                Case "MD"
                    Me.lblResult.Text = "Maryland"
                Case "MA"
                    Me.lblResult.Text = "Massachusets"
                Case "MI"
                    Me.lblResult.Text = "Michigan"
                Case "MN"
                    Me.lblResult.Text = "Minnesota"
                Case "MS"
                    Me.lblResult.Text = "Mississippi"
                Case "MO"
                    Me.lblResult.Text = "Missouri"
                Case "MT"
                    Me.lblResult.Text = "Montana"
                Case "NE"
                    Me.lblResult.Text = "Nebraska"
                Case "NV"
                    Me.lblResult.Text = "Nevada"
                Case "NH"
                    Me.lblResult.Text = "New Hampshire"
                Case "NJ"
                    Me.lblResult.Text = "New Jearsy"
                Case "NM"
                    Me.lblResult.Text = "New Mexico"
                Case "NY"
                    Me.lblResult.Text = "New York"
                Case "NC"
                    Me.lblResult.Text = "North Caroline"
                Case "ND"
                    Me.lblResult.Text = "North Dakota"
                Case "OH"
                    Me.lblResult.Text = "Ohio"
                Case "OK"
                    Me.lblResult.Text = "Oklahoma"
                Case "OR"
                    Me.lblResult.Text = "Oregon"
                Case "PA"
                    Me.lblResult.Text = "Pennsylvania"
                Case "RI"
                    Me.lblResult.Text = "Rhode Island"
                Case "SC"
                    Me.lblResult.Text = "South Carolina"
                Case "SD"
                    Me.lblResult.Text = "South Dekota"
                Case "TN"
                    Me.lblResult.Text = "Tennessee"
                Case "TX"
                    Me.lblResult.Text = "Texas"
                Case "UT"
                    Me.lblResult.Text = "Utah"
                Case "VT"
                    Me.lblResult.Text = "Vermont"
                Case "VA"
                    Me.lblResult.Text = "Virginia"
                Case "WA"
                    Me.lblResult.Text = "Washington"
                Case "WV"
                    Me.lblResult.Text = "West Virginia"
                Case "WI"
                    Me.lblResult.Text = "Wisconsin"
                Case "WY"
                    Me.lblResult.Text = "Wyoming"
                Case Else
                    MsgBox("Enter a valid abriviaiton", MsgBoxStyle.OkCancel Or MsgBoxStyle.Critical, "User Input Error")
                    Me.txtAbriviation.Clear()
                    Me.txtAbriviation.Focus()
    
            End Select
    
        End Sub

    This code works fine when user enters Capital letters. It's just that i want it to work if user enters small letters.
    Last edited by nidhishah; Mar 18th, 2010 at 12:30 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to use To.Upper Procedure?

    Look at your own code and ask yourself what it's actually doing:
    Code:
    strAbriviation = Convert.ToString(Me.txtAbriviation.Text)
    strAbriviation = strAbriviation.ToUpper(txtAbriviation.Text)
    That first line is taking the Text from the TextBox, which is a String, converting it to a String and then assigning that to the variable. Why would you want to convert a String to a String?

    As for the second line, the variable already contains the Text from the TextBox and you're calling ToUpper on that variable, why would you need to get the Text from the TextBox again? Don't just pass whatever to a variable. As you type, pay attention to what Intellisense tells you. It tells you exactly what parameters the method has and exactly what they mean. At no point would Intellisense have told you to pass a String as an argument to ToUpper. I suggest that you delete that code and start typing it again, this time reading the tool tips that Intellisense displays. You might also consider reading the documentation for the String.ToUpper method. The sooner you can learn these techniques, the sooner you can solve problems like this for yourself, or avoid them altogether.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    60

    Re: How to use To.Upper Procedure?

    My book says the general format for upper case procedure is :

    Code:
    strName = strName.ToUpper()
    It doesn't give any example or anything. That's why i'm confused and wrote like this.

  4. #4

    Re: How to use To.Upper Procedure?

    Your book is right. All you're doing is making the string (strName) in complete capital letters with the .ToUpper() method.
    Code:
    Dim str As String = "text"
    str = str.ToUpper()
    'Now str = TEXT

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    60

    Re: How to use To.Upper Procedure?

    Quote Originally Posted by formlesstree4 View Post
    Your book is right. All you're doing is making the string (strName) in complete capital letters with the .ToUpper() method.
    Code:
    Dim str As String = "text"
    str = str.ToUpper()
    'Now str = TEXT
    so you mean i replace str with strAbriviation right?
    it didn't work

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to use To.Upper Procedure?

    If you did it correctly then it would have worked, so you must not have done it correctly. If you just say "it didn't work" without showing us what "it" is, i.e. your code, then we can't tell you why it didn't work.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    60

    Re: How to use To.Upper Procedure?

    ok how about this? am i on right track?

    Code:
    Dim strAbriviation As String
    Me.txtAbriviation.Text = strAbriviation.ToUpper()

  8. #8

    Re: How to use To.Upper Procedure?

    Um...you never assigned strAbriviation a value. That's like trying to pour water into a glass when you have no glass...you just get a mess.

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    60

    Re: How to use To.Upper Procedure?

    Code:
    Dim strAbriviation As String = ""
    
            Select Case Me.txtAbriviation.Text
                Case "AL"
                    Me.lblResult.Text = "Alabama"
                    Me.txtAbriviation.Text = strAbriviation.ToUpper()
    I tried this but it still doesnt convert the textbox in capital letters

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to use To.Upper Procedure?

    Quote Originally Posted by nidhishah View Post
    Code:
    Dim strAbriviation As String = ""
    
            Select Case Me.txtAbriviation.Text
                Case "AL"
                    Me.lblResult.Text = "Alabama"
                    Me.txtAbriviation.Text = strAbriviation.ToUpper()
    I tried this but it still doesnt convert the textbox in capital letters
    Where in that code have you assigned anything other than an empty string to strAbriviation? Don't you have to actually put the abbreviation into the variable before you can convert it to upper case? Also, you might want to fix that spelling.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    60

    Re: How to use To.Upper Procedure?

    like this??????
    Code:
    Dim strAbriviation As String = "text"
    strAbriviation = strAbriviation.ToUpper()
    Oh gosh I'm so gonna cry. I'm really not getting this.

  12. #12

    Re: How to use To.Upper Procedure?

    Yes, like that...you got to assign a value first to the string as I said back in post #8.

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    60

    Re: How to use To.Upper Procedure?

    Quote Originally Posted by formlesstree4 View Post
    Yes, like that...you got to assign a value first to the string as I said back in post #8.
    ya but this is giving me an error message box.

  14. #14

    Re: How to use To.Upper Procedure?

    Do you mind posting what the actual error is rather than just telling us one is showing?

  15. #15

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    60

    Re: How to use To.Upper Procedure?

    Ya sure,
    When I put abriviation in small letters even after assigning value to string, this code enables.

    Code:
    Case Else
                    MsgBox("Enter a valid abriviaiton", MsgBoxStyle.OkCancel Or MsgBoxStyle.Critical, "User Input Error")
                    Me.txtAbriviation.Clear()
                    Me.txtAbriviation.Focus()
    and gives me error box msg

  16. #16

    Re: How to use To.Upper Procedure?

    *rubs eyes* Ok, let's try this again.
    vb.net Code:
    1. Select Case Me.txtAbriviation.Text
    2.             Case "AL"
    3.                 Me.lblResult.Text = "Alabama"
    4.             Case "AK"
    5.                 Me.lblResult.Text = "Alaska"
    6.             Case "AZ"
    7.                 Me.lblResult.Text = "Arizona"
    8.             Case "AR"
    9.                 Me.lblResult.Text = "Arkansas"
    10.             Case "CA"
    11.                 Me.lblResult.Text = "California"
    12.             Case "CO"
    13.                 Me.lblResult.Text = "Colorado"
    14.             Case "CT"
    15.                 Me.lblResult.Text = "Conneticut"
    16.             Case "DE"
    17.                 Me.lblResult.Text = "Delaware"
    18.             Case "FL"
    19.                 Me.lblResult.Text = "Florida"
    20.             Case "GA"
    21.                 Me.lblResult.Text = "Georgia"
    22.             Case "HI"
    23.                 Me.lblResult.Text = "Hawaii"
    24.             Case "ID"
    25.                 Me.lblResult.Text = "Idaho"
    26.             Case "IL"
    27.                 Me.lblResult.Text = "Illinois"
    28.             Case "IN"
    29.                 Me.lblResult.Text = "Indiana"
    30.             Case "IA"
    31.                 Me.lblResult.Text = "Iowa"
    32.             Case "KS"
    33.                 Me.lblResult.Text = "Kansas"
    34.             Case "KY"
    35.                 Me.lblResult.Text = "Kentucky"
    36.             Case "LA"
    37.                 Me.lblResult.Text = "Louisiana"
    38.             Case "ME"
    39.                 Me.lblResult.Text = "Maine"
    40.             Case "MD"
    41.                 Me.lblResult.Text = "Maryland"
    42.             Case "MA"
    43.                 Me.lblResult.Text = "Massachusets"
    44.             Case "MI"
    45.                 Me.lblResult.Text = "Michigan"
    46.             Case "MN"
    47.                 Me.lblResult.Text = "Minnesota"
    48.             Case "MS"
    49.                 Me.lblResult.Text = "Mississippi"
    50.             Case "MO"
    51.                 Me.lblResult.Text = "Missouri"
    52.             Case "MT"
    53.                 Me.lblResult.Text = "Montana"
    54.             Case "NE"
    55.                 Me.lblResult.Text = "Nebraska"
    56.             Case "NV"
    57.                 Me.lblResult.Text = "Nevada"
    58.             Case "NH"
    59.                 Me.lblResult.Text = "New Hampshire"
    60.             Case "NJ"
    61.                 Me.lblResult.Text = "New Jearsy"
    62.             Case "NM"
    63.                 Me.lblResult.Text = "New Mexico"
    64.             Case "NY"
    65.                 Me.lblResult.Text = "New York"
    66.             Case "NC"
    67.                 Me.lblResult.Text = "North Caroline"
    68.             Case "ND"
    69.                 Me.lblResult.Text = "North Dakota"
    70.             Case "OH"
    71.                 Me.lblResult.Text = "Ohio"
    72.             Case "OK"
    73.                 Me.lblResult.Text = "Oklahoma"
    74.             Case "OR"
    75.                 Me.lblResult.Text = "Oregon"
    76.             Case "PA"
    77.                 Me.lblResult.Text = "Pennsylvania"
    78.             Case "RI"
    79.                 Me.lblResult.Text = "Rhode Island"
    80.             Case "SC"
    81.                 Me.lblResult.Text = "South Carolina"
    82.             Case "SD"
    83.                 Me.lblResult.Text = "South Dekota"
    84.             Case "TN"
    85.                 Me.lblResult.Text = "Tennessee"
    86.             Case "TX"
    87.                 Me.lblResult.Text = "Texas"
    88.             Case "UT"
    89.                 Me.lblResult.Text = "Utah"
    90.             Case "VT"
    91.                 Me.lblResult.Text = "Vermont"
    92.             Case "VA"
    93.                 Me.lblResult.Text = "Virginia"
    94.             Case "WA"
    95.                 Me.lblResult.Text = "Washington"
    96.             Case "WV"
    97.                 Me.lblResult.Text = "West Virginia"
    98.             Case "WI"
    99.                 Me.lblResult.Text = "Wisconsin"
    100.             Case "WY"
    101.                 Me.lblResult.Text = "Wyoming"
    102.             Case Else
    103.                 MsgBox("Enter a valid abriviaiton", MsgBoxStyle.OkCancel Or MsgBoxStyle.Critical, "User Input Error")
    104.                 Me.txtAbriviation.Clear()
    105.                 Me.txtAbriviation.Focus()
    106.  
    107.         End Select
    That is your original code. You're testing for what the Text of the TextBox is, correct? So, modify the Select Case part of your code from this:
    vb.net Code:
    1. Select Case Me.txtAbriviation.Text
    To this:
    vb.net Code:
    1. Select Case Me.txtAbriviation.Text.ToUpper()
    The code you were using wouldn't have fired anything but the Else because never did you actually change the text in the TextBox to Upper Case. Now it does that, and you can even change the text of the TextBox to Upper like this:
    vb.net Code:
    1. Me.txtAbriviation.Text = Me.txtAbriviation.Text.ToUpper()

  17. #17

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    60

    Re: How to use To.Upper Procedure?

    OMG...how simple was that...why the heck I wasn't getting this?

    Hey thank you so much !!!

  18. #18

    Re: [Resolved]How to use To.Upper Procedure?

    Glad to help, hope everything works 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