Solved

Simplifying select case statement

Posted on 2013-11-30
2
423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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