Solved

StartsWith Select Case

Posted on 2006-10-27
3
1,020 Views
Last Modified: 2008-01-09
Is there a slick way to use the StartsWith in combination with a Select/Case? Something like this (which doesn't compile):

        Select Case TextBox1.Text.ToUpper
            Case String.StartsWith("AB")
            ' ...
        End Select

Instead of a bunch of:

 If TextBox1.Text.ToUpper.StartsWith("AB") Then
 ElseIf ..  ("CD")

and so on.
0
Comment
Question by:GivenRandy
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 300 total points
ID: 17821466
No, Case allows only constants. Do this with If - ElseIf - Else operator.
0
 
LVL 1

Assisted Solution

by:super786
super786 earned 200 total points
ID: 17821492
If you can define the length of your search string (ie, 2 characters) then you can do:

Select Case TextBox1.Text.SubString(0, 2).ToUpper()
   Case "AB"
   Case "CD"
   Case "EF"
end select

but if you have a variable length search string, then you can't do it unless you can specify a delimiter or something.  Ie, all strings start with the code string followed by a colon (:).  Then you can pull the string up to the colon before you run it through the select case.
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 17821597
That's the way I had done it. Didn't know if they was some Framework trick I was missing (the thing is massive).
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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