|
-
Mar 16th, 2010, 11:18 PM
#1
Thread Starter
Member
[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.
-
Mar 16th, 2010, 11:41 PM
#2
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.
-
Mar 16th, 2010, 11:52 PM
#3
Thread Starter
Member
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.
-
Mar 17th, 2010, 12:03 AM
#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
-
Mar 17th, 2010, 12:23 AM
#5
Thread Starter
Member
Re: How to use To.Upper Procedure?
 Originally Posted by formlesstree4
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
-
Mar 17th, 2010, 12:40 AM
#6
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.
-
Mar 17th, 2010, 01:20 AM
#7
Thread Starter
Member
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()
-
Mar 17th, 2010, 03:12 AM
#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.
-
Mar 17th, 2010, 11:36 PM
#9
Thread Starter
Member
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
-
Mar 17th, 2010, 11:41 PM
#10
Re: How to use To.Upper Procedure?
 Originally Posted by nidhishah
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.
-
Mar 17th, 2010, 11:49 PM
#11
Thread Starter
Member
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.
-
Mar 17th, 2010, 11:57 PM
#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.
-
Mar 18th, 2010, 12:01 AM
#13
Thread Starter
Member
Re: How to use To.Upper Procedure?
 Originally Posted by formlesstree4
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.
-
Mar 18th, 2010, 12:02 AM
#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?
-
Mar 18th, 2010, 12:11 AM
#15
Thread Starter
Member
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
-
Mar 18th, 2010, 12:19 AM
#16
Re: How to use To.Upper Procedure?
*rubs eyes* Ok, let's try this again.
vb.net Code:
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
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:
Select Case Me.txtAbriviation.Text
To this:
vb.net Code:
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:
Me.txtAbriviation.Text = Me.txtAbriviation.Text.ToUpper()
-
Mar 18th, 2010, 12:29 AM
#17
Thread Starter
Member
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 !!!
-
Mar 18th, 2010, 12:44 AM
#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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|