Solved

Simplifying select case statement

Posted on 2013-11-30
2
417 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get Top Visible Row of Datagridview 6 32
Help with AsEnumerable(), LINQ 4 38
EF5: Question about Metadata Artifact Processing 4 15
VB.net and sql server 4 33
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

10 Experts available now in Live!

Get 1:1 Help Now