|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Having trouble with the ToUpper method
Ok, im in a VB class and for homework my professor gave the class an assignment where we needed to detect what the middle character of a 5 character string was and if that letter was a b or B then a label would display the word Blue.
So far my code looks like this Code:
Dim item As String item = itemTextBox.Text If item.Substring(2, 1) = "b" Then colorLabel.Text = "Blue" End If everywhere ive tried placing the .ToUpper Method has resulting in the code not working for "b" or "B" despite there being no error's in the code. I next tried Cases instead of If statements and used this code Code:
Select Case item.ToUpper.Substring(2, 1)
Case "B"
colorLabel.Text = "Blue"
End Select
and this code works perfectly for "b" and "B" as the center character in the 5 character string. However i'd like to do this using an If statement. Is it possible? If it is then can someone please point me as to where i need to place the ToUpper method in the first code i posted to make it work for "b" and "B"? Thanks. |
|
#2
|
||||
|
||||
|
You if doesn't work when you add ToUpper() because a "b" would become "B", so it can't possibly equal "b". Your case works because you are doing ToUpper(), and comparing it to "B".
|
|
#3
|
|||
|
|||
|
Quote:
Well i ended up submitting this homework using the cases, but thanks for the reply. What you said worked though i could have sworn i tried that when i was working on this lol. Well now its knowledge i can use another day. Thanks. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Having trouble with the ToUpper method |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|