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
Solved

Simplifying select case statement

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net Open Folder in Windows Explorer 3 50
Footer for each row on Gridview 2 32
Help with consolidating excel files using VB.net 2 29
vb.net winforms sizing/resolution? 4 40
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 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