Solved

Simplifying select case statement

Posted on 2013-11-30
2
410 Views
Last Modified: 2013-12-03
In the below select case statement I am checking to see if the character in a string is alphabetic.
Select Case char
     Case "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
          Do something
End Select

Open in new window

What I would like to know is if there is a simpler way of doing this, like:
case "a" to "z"
or
if char="a" to "z"
0
Comment
Question by:NevSoFly
2 Comments
 
LVL 13

Assisted Solution

by:duncanb7
duncanb7 earned 250 total points
ID: 39687802
Just example  and partial code only, you can change e.KeyChar for your char or method variable

Hope understand your question completely. If not , please pt it out

Duncan

Dim KeyAscii As Integer
        KeyAscii = Asc(e.KeyChar)
        Select Case KeyAscii
case 65 to 90    ''for capital ALPHABET A-Z
case 97  to 122    'lower case a-z
case else

Open in new window

0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 250 total points
ID: 39687965
Actually, your own first suggestion is perfectly valid:
Select Case [char]
     Case "a" To "z"
          'Do something
End Select

Open in new window

However, there is a more generic way to do this and it includes letters with accents and the likes so not just "a" to "z" but also "é" for example:
     Dim [char] As Char = TextBox1.Text.Substring(0, 1).ToLower()
     If Char.IsLetter([char]) Then
          ' ...
     End If

Open in new window

Note that I used [char] to make it a valid variable name from your code example, and "Char.IsLetter" refers to a static method in the Char class.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now