473,385 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Select Case Problem

Hello,

This is gonna sound real daft, but how do I test a Select Case statement for
variants of a theme?

Here's a snippet of my code...

Select Case sUsr
Case "Guest", "TsInternetUser", "krbtgt", "quality7"
' don't show
Case Left(sUsr, 13) = "SystemMailbox"
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select

What i'm trying to do is find any sUsr variable that begins with
'SystemMailbox' and exclude it. If I use the code shown above it helpfully
informs me that the input string is not in the correct format. Is there any
way of using wildcards, or making the above sample correct?

Cheers,

Mike
Nov 21 '05 #1
8 4691
Hi Mike

Select Case True
Case sUsr = "Guest", sUsr = "TsInternetUser", sUsr = "krbtgt", sUsr =
"quality7"
' don't show
Case sUsr.StartsWith("SystemMailbox")
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select

HTH

Charles
"<M>ike" <mikedotdinnisatabraxas-ukdotcom> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello,

This is gonna sound real daft, but how do I test a Select Case statement
for
variants of a theme?

Here's a snippet of my code...

Select Case sUsr
Case "Guest", "TsInternetUser", "krbtgt", "quality7"
' don't show
Case Left(sUsr, 13) = "SystemMailbox"
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select

What i'm trying to do is find any sUsr variable that begins with
'SystemMailbox' and exclude it. If I use the code shown above it helpfully
informs me that the input string is not in the correct format. Is there
any
way of using wildcards, or making the above sample correct?

Cheers,

Mike

Nov 21 '05 #2
Charles,

It does indeed work, thank you. I have read elsewhere that this form of
Select Case statement can be troublesome and others have discouraged it's
use. Do you have experience of this type of syntax and have you had any
problems with it in the past?

Cheers,

<M>ike

"Charles Law" <bl***@nowhere.com> wrote in message
news:u7**************@TK2MSFTNGP15.phx.gbl...
Hi Mike

Select Case True
Case sUsr = "Guest", sUsr = "TsInternetUser", sUsr = "krbtgt", sUsr =
"quality7"
' don't show
Case sUsr.StartsWith("SystemMailbox")
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select

HTH

Charles
"<M>ike" <mikedotdinnisatabraxas-ukdotcom> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello,

This is gonna sound real daft, but how do I test a Select Case statement
for
variants of a theme?

Here's a snippet of my code...

Select Case sUsr
Case "Guest", "TsInternetUser", "krbtgt", "quality7"
' don't show
Case Left(sUsr, 13) = "SystemMailbox"
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select

What i'm trying to do is find any sUsr variable that begins with
'SystemMailbox' and exclude it. If I use the code shown above it helpfully informs me that the input string is not in the correct format. Is there
any
way of using wildcards, or making the above sample correct?

Cheers,

Mike


Nov 21 '05 #3
Mike

I personally don't like it, although I use it in just such scenarios as you
illustrated. It is a kludge to get round (what seems to me) a deficiency in
the Select Case construct. The necessity to repeat the 'sUsr = ' makes it a
bit ugly,and it also has the (minor) disadvantage that intellisense does not
work as desired on the Case statements.

As far as problems are concerned, I haven't really had any but, as I say, I
try to avoid using it if I can.

Charles
"<M>ike" <mikedotdinnisatabraxas-ukdotcom> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
Charles,

It does indeed work, thank you. I have read elsewhere that this form of
Select Case statement can be troublesome and others have discouraged it's
use. Do you have experience of this type of syntax and have you had any
problems with it in the past?

Cheers,

<M>ike

"Charles Law" <bl***@nowhere.com> wrote in message
news:u7**************@TK2MSFTNGP15.phx.gbl...
Hi Mike

Select Case True
Case sUsr = "Guest", sUsr = "TsInternetUser", sUsr = "krbtgt", sUsr =
"quality7"
' don't show
Case sUsr.StartsWith("SystemMailbox")
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select

HTH

Charles
"<M>ike" <mikedotdinnisatabraxas-ukdotcom> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> Hello,
>
> This is gonna sound real daft, but how do I test a Select Case
> statement
> for
> variants of a theme?
>
> Here's a snippet of my code...
>
> Select Case sUsr
> Case "Guest", "TsInternetUser", "krbtgt", "quality7"
> ' don't show
> Case Left(sUsr, 13) = "SystemMailbox"
> ' don't show
> Case Else
> ListBox1.Items.Add(sUsr)
> End Select
>
> What i'm trying to do is find any sUsr variable that begins with
> 'SystemMailbox' and exclude it. If I use the code shown above it helpfully > informs me that the input string is not in the correct format. Is there
> any
> way of using wildcards, or making the above sample correct?
>
> Cheers,
>
> Mike
>
>



Nov 21 '05 #4
Charles,

I was thinking about a same kind of sample as you made and thought, that is
not the way to go.

However it is nicely done

:-)

Cor
Nov 21 '05 #5
JD
Looking at your code, the thing that is bothersome is that you are actually
doing three things in the single select statement.

1. Performing filtering logic on the test expression (sUsr)

2. Deciding whether to add the user to the list box.

3. Adding the item to the list box
There is nothing wrong with this and it is really a matter of style, but
when someone reads your single select statement they have to come to a
realization of really what your intentions are. If clean code, readability
and maintainability is a concern, one suggestion is you might want to split
these up to seperate methods, each method doing exactly one thing and the
method name describing exactly what it is trying to do. Again its only a
matter of style and my opinion.

'Prefilter logic
Private Function FilterUsers(ByVal User As String) As String
If User.StartsWith("SystemMailbox") Then
Return "SystemMailbox"
Else
Return User
End If
End Function

'Decision whether to add
Private Function ShouldAddToListBox(ByVal User As String) As Boolean
Dim Result As Boolean = False
Select Case User
Case "Guest", "TsInternetUser", "krbtgt", "quality7",
"SystemMailbox"
Result = False
Case Else
Result = True
End Select
Return Result
End Function
'Actual add to list box
Private Sub AddToListBox(ByVal User As String)
If ShouldAddToListBox(FilterUsers(User)) Then
LB.Items.Add(User)
End If
End Sub
"<M>ike" <mikedotdinnisatabraxas-ukdotcom> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
Charles,

It does indeed work, thank you. I have read elsewhere that this form of
Select Case statement can be troublesome and others have discouraged it's
use. Do you have experience of this type of syntax and have you had any
problems with it in the past?

Cheers,

<M>ike

"Charles Law" <bl***@nowhere.com> wrote in message
news:u7**************@TK2MSFTNGP15.phx.gbl...
Hi Mike

Select Case True
Case sUsr = "Guest", sUsr = "TsInternetUser", sUsr = "krbtgt", sUsr =
"quality7"
' don't show
Case sUsr.StartsWith("SystemMailbox")
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select

HTH

Charles
"<M>ike" <mikedotdinnisatabraxas-ukdotcom> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello,

This is gonna sound real daft, but how do I test a Select Case statement for
variants of a theme?

Here's a snippet of my code...

Select Case sUsr
Case "Guest", "TsInternetUser", "krbtgt", "quality7"
' don't show
Case Left(sUsr, 13) = "SystemMailbox"
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select

What i'm trying to do is find any sUsr variable that begins with
'SystemMailbox' and exclude it. If I use the code shown above it helpfully informs me that the input string is not in the correct format. Is there any
way of using wildcards, or making the above sample correct?

Cheers,

Mike



Nov 21 '05 #6
I guess I'm from the old school but it seems that an IF then else statement
would work just fine here;

if left(sUsr) = "SystemMailBox" orelse sUsr="Guest" orelse...... then
'do nothing
else
ListBox1.Items.Add(sUsr)

end if

"<M>ike" wrote:
Hello,

This is gonna sound real daft, but how do I test a Select Case statement for
variants of a theme?

Here's a snippet of my code...

Select Case sUsr
Case "Guest", "TsInternetUser", "krbtgt", "quality7"
' don't show
Case Left(sUsr, 13) = "SystemMailbox"
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select

What i'm trying to do is find any sUsr variable that begins with
'SystemMailbox' and exclude it. If I use the code shown above it helpfully
informs me that the input string is not in the correct format. Is there any
way of using wildcards, or making the above sample correct?

Cheers,

Mike

Nov 21 '05 #7
What i'm trying to do is find any sUsr variable that begins with
'SystemMailbox' and exclude it. If I use the code shown above it helpfully
informs me that the input string is not in the correct format. Is there any way of using wildcards, or making the above sample correct?

I've been trying to work on my 'regular expressions' skills, and have a long
way to go,
Wouldn't this type of search be the kind of thing that 'regular expressions'
can help with ?

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 9/17/2004
Nov 21 '05 #8
Hello Mike

You cannot do this: Case Left(sUsr, 13) = "SystemMailbox"
That will throw an exception.

In this case I would simply do conditional statements like

If sUsr = "Guest" AndAlso sUsr = "TsInternetUser" AndAlso "krbtgt" Then
'do nothing
ElseIf Left(sUsr, 13) = "SystemMailbox" Then
'do nothing
Else
ListBox1.Items.Add(sUsr)
End If

Something like that...
Hello,

This is gonna sound real daft, but how do I test a Select Case
statement for variants of a theme?

Here's a snippet of my code...

Select Case sUsr
Case "Guest", "TsInternetUser", "krbtgt", "quality7"
' don't show
Case Left(sUsr, 13) = "SystemMailbox"
' don't show
Case Else
ListBox1.Items.Add(sUsr)
End Select
What i'm trying to do is find any sUsr variable that begins with
'SystemMailbox' and exclude it. If I use the code shown above it
helpfully informs me that the input string is not in the correct
format. Is there any way of using wildcards, or making the above
sample correct?

Cheers,

Mike


Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
0
by: Michael | last post by:
I have a problem forcing files to download. If I select Save the document is saved with no problems. If I select "Open" the document is empty or I get a "File not found" error from the application...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
2
by: JMCN | last post by:
hello i have your basic select case question. i created a combo box and save it as a query. so whenever the user selects the value and clicks the export button, the select case should then export...
10
by: MLH | last post by:
Suppose the following... Dim A as Date A=#7/24/2005# I wish to compare value of A against 2 other values: 1) 8/1/2005 2) 9/1/2005 Which is better and why... First:
3
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL =...
2
by: scole954387 | last post by:
Hi, I have a problem. I have written a SQL statement that has a nested select case statement on the 'where' clause to condition the results. ...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.