Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old April 26th, 2008, 07:54 PM
Symbolite Symbolite is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 Symbolite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 43 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old April 28th, 2008, 09:46 AM
LyonHaert's Avatar
LyonHaert LyonHaert is online now
Arcane Scribbler
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2005
Location: Indianapolis, IN
Posts: 1,596 LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 13 h 37 m 2 sec
Reputation Power: 364
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".
__________________
Joel B Fant - LyonHaert.net

2 + 2 is... 10... in base 4

Reply With Quote
  #3  
Old April 29th, 2008, 10:59 AM
Symbolite Symbolite is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 Symbolite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 43 sec
Reputation Power: 0
Quote:
Originally Posted by LyonHaert
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".


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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Having trouble with the ToUpper method


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway