SELECT CASE in ASP???

N

Newbie

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 allow entry to one or the other
or Both at the same time. Now I tried to use an If ElseIf but it got too
hard to track, so now I am using a SELECT CASE Statement.

TEXBOX1 named strEnglish
TEXBOX2 named strFrench

My code:
<%
strEnglish=Request.Form("strEnglish")
strFrench=Request.Form("strFrench")

Select Case

Then I have no idea how to go from here, because I have 2 input textboxes to
follow.


I found this example but I do not know how to apply it to my situation as I
have to folow 2 textbox entries.

<%
UserName=request.form("UserName")
Select Case UserName
Case "Kathi"
Msg = "You deserve a break. Take the day off!"
Case "JD","Anne"
Msg = "Don't forget to call Kathi today!"
Case Else
Msg = "Do I know you?"
End Select
response.write Msg
%>

Can someone please help me out, a known tutorial, perhaps an example or just
plain good ole help please??

Thanks in advance,

~Newbie
 
E

Evertjan.

Newbie wrote on 07 aug 2004 in microsoft.public.inetserver.asp.general:
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 allow entry to one or the
other or Both at the same time. Now I tried to use an If ElseIf but
it got too hard to track, so now I am using a SELECT CASE Statement.

TEXBOX1 named strEnglish
TEXBOX2 named strFrench

My code:
<%
strEnglish=Request.Form("strEnglish")
strFrench=Request.Form("strFrench")

Select Case

Then I have no idea how to go from here, because I have 2 input
textboxes to follow.

It is not that I cannot dint a solution using select case in this case,
but it seems far more useful to know what you want to do with the two
strings.

Probably you do not want to use select case after all!!

<%
strEnglish=Request.Form("strEnglish")
strFrench=Request.Form("strFrench")

if strEnglish = strFrench then
t="This is very improbable"
else
t="Two different languages usually produce different strings"
end if
response.write t
%>

not tested, but it should be the same as:

<%
strEnglish=Request.Form("strEnglish")
strFrench=Request.Form("strFrench")

select case strEnglish
case strFrench
t="This is very improbable"
case else
t="Two different languages usually produce different strings"
end select
response.write t
%>
 
D

dlbjr

Function GetResult(str1,str2)
strkey = Trim(str1) & Trim(str2)
Select Case strkey
Case "WhatEver1"
GetResult = "Something1"
Case "WhatEver2"
GetResult = "Something2"
Case "WhatEver3"
GetResult = "Something3"
Case "WhatEver4"
GetResult = "Something4"
End Select
End Function

dlbjr
Pleading sagacious indoctrination!
 
B

Brad

This entire thing is rather embarrassing as I cannto get it to work.

I have 2 input strings that will contain URL's (the contents of the textbox
strings is a non-issue.

I have to allow the user to be able to enter into JUST the English OR Just
the FRENCH or be able to Enter into BOTH ENGLISH and FRENCH

I was using an IF ELSE statement but was having a hard time with it, as the
scenerio's conflicted.

Example:

If strEnglish<>empty AND strFrench <>empty Then 'Both have something inside
them
'ENTER BOTH INTO DB
End If

If strEnglish<>empty Then 'Just English has something
inside it
'ENTER JUST THE ENGLISH
End If

If strFrench<>empty Then 'Just French has something
inside it
'ENTER JUST THE FRENCH
End If


Now for BOTH of the string textbox inputs , it worked well, but if I just
entered on either ENGLISH or FRENCH, well it would not acknowledge it......

So I think that maybe I should be using a CASE SELECT..but now I have no
idea how to make that work for my code, especially in ASP.

SAD yet true...but willing to learn how to make it work..........but have
yet to find an example that will make me understand..perhaps I am making it
harder than it is...a usual problem of mine.;))

Can someone help me out here, as I am having a hard time to get this to
work.

Thanks in advance,

~Brad (NEWBIE to ASP CASE Selects)
 
B

Brad

This entire thing is rather embarrassing as I cannto get it to work.

I have 2 input strings that will contain URL's (the contents of the textbox
strings is a non-issue.

I have to allow the user to be able to enter into JUST the English OR Just
the FRENCH or be able to Enter into BOTH ENGLISH and FRENCH

I was using an IF ELSE statement but was having a hard time with it, as the
scenerio's conflicted.

Example:

If strEnglish<>empty AND strFrench <>empty Then 'Both have something inside
them
'ENTER BOTH INTO DB
End If

If strEnglish<>empty Then 'Just English has something
inside it
'ENTER JUST THE ENGLISH
End If

If strFrench<>empty Then 'Just French has something
inside it
'ENTER JUST THE FRENCH
End If


Now for BOTH of the string textbox inputs , it worked well, but if I just
entered on either ENGLISH or FRENCH, well it would not acknowledge it......

So I think that maybe I should be using a CASE SELECT..but now I have no
idea how to make that work for my code, especially in ASP.

SAD yet true...but willing to learn how to make it work..........but have
yet to find an example that will make me understand..perhaps I am making it
harder than it is...a usual problem of mine.;))

Can someone help me out here, as I am having a hard time to get this to
work.

Thanks in advance,

~Brad (NEWBIE to ASP CASE Selects)
 
B

Brad

If strEnglish<>empty AND strFrench<>empty Then
'Do Both
End If

If strEnglish<>empty Then
'Do JUSt the English one
ElseIF strFrench<>empty Then
'Do Just the French one
End If

I did not need to use a SELECT CASE........... I think I must have missed
something when Iw first wrote the IF ELSEIF

Well now it works for all scenerios,

Thanks again to all those for your input............it is always helpful

~Brad

www.webdevcreations.com
 
C

Chris Hohmann

Brad said:
If strEnglish<>empty AND strFrench<>empty Then
'Do Both
End If

If strEnglish<>empty Then
'Do JUSt the English one
ElseIF strFrench<>empty Then
'Do Just the French one
End If

I did not need to use a SELECT CASE........... I think I must have missed
something when Iw first wrote the IF ELSEIF

Well now it works for all scenerios,

Thanks again to all those for your input............it is always helpful

Doesn't the above logic indicate that all three cases (English, French and
both) will be executed when both English and French are present? I think
this is the logic you're after:

If Len(strEnglish & strFrench)=0 Then
'Neither is present
ElseIf Len(strEnglish)=0 Then
'French
ElseIf Len(strFrench)=0 Then
'English
Else
'Both
End If

IMPORTANT NOTE: Pay special attention to "ElseIf". It's one word, no spaces.
It's fundamentally different from "Else If", which denotes nested IF
statements. Also, are you actually using the IsEmpty() inspection function?
It doesn't do what I think you think it does. :)
 
B

Brad

Chris,

I ran into problems with my Logic thinking of If Else, rather than
IFELSE.....finding out the hard way that my If strEnglish<>empty did not
work, nor did the one for the french......

So I finally ended up with what yoru logic depicted.

Thanks for the help [IE: your Important Note;)) ],

~Brad
 
B

Brad

Chris,

Seems the logic is not working..............

It works very well for BOTH, but not for the rest, any ideas?

Perhaps I should use a CASE SELECT

How can I convert the logic you wrote to CASE SELECT

I cannot make it work with the IFELSE, it seems to crap out on the
individual entries, while the BOTh entries works fine.

Any ideas?

Thanks in advance,

~Brad


Brad said:
Chris,

I ran into problems with my Logic thinking of If Else, rather than
IFELSE.....finding out the hard way that my If strEnglish<>empty did not
work, nor did the one for the french......

So I finally ended up with what yoru logic depicted.

Thanks for the help [IE: your Important Note;)) ],

~Brad



Chris Hohmann said:
helpful

Doesn't the above logic indicate that all three cases (English, French and
both) will be executed when both English and French are present? I think
this is the logic you're after:

If Len(strEnglish & strFrench)=0 Then
'Neither is present
ElseIf Len(strEnglish)=0 Then
'French
ElseIf Len(strFrench)=0 Then
'English
Else
'Both
End If

IMPORTANT NOTE: Pay special attention to "ElseIf". It's one word, no spaces.
It's fundamentally different from "Else If", which denotes nested IF
statements. Also, are you actually using the IsEmpty() inspection function?
It doesn't do what I think you think it does. :)
 
E

Evertjan.

Brad wrote on 07 aug 2004 in
microsoft.public.inetserver.asp.general:
Now for BOTH of the string textbox inputs , it worked well,
but if I just entered on either ENGLISH or FRENCH, well it
would not acknowledge it......

So I think that maybe I should be using a CASE SELECT..
but now I have no idea how to make that work for my code,

Use the "Elseif" clause:

If a="" AND b="" Then
'do what needs to be done if both are empty
Elseif a="" Then
'do what needs to be done if only a is empty
Elseif b="" Then
'do what needs to be done if only b is empty
Else
'do what needs to be done if both are filled
End If

The 'select case' is never necessary, it only gives a
better visual appearance and preferably one variable to
be tested for a lot of values and intervals.

The 'if-then..elseif-then..else..end if' is also pleasing
to the eye,[and therefore easily debuggable IMHO,]
if properly indented.
especially in ASP.

ASP is not a scripting language. We are talking vbscript
here, and wether this is done in a serverside ASP platform
or in IE clientside vbscript does not matter, if you do not
use specific ASP objects like Response or Server. Those
objects are not part of vbscript and are also available in
ASP j(ava)script etc.
 
B

Bob Barrows [MVP]

Evertjan. said:
Brad wrote on 07 aug 2004 in
microsoft.public.inetserver.asp.general:


Use the "Elseif" clause:

If a="" AND b="" Then
'do what needs to be done if both are empty
Elseif a="" Then
'do what needs to be done if only a is empty
Elseif b="" Then
'do what needs to be done if only b is empty
Else
'do what needs to be done if both are filled
End If

The 'select case' is never necessary, it only gives a
better visual appearance and preferably one variable to
be tested for a lot of values and intervals.

The advantage of select case is that it utilizes short-circuit evaluation,
as opposed to If, in which all expressions are evaluated, which can lead to
errors if any of the expressions generate errors depending on the results of
earlier evaluations. I realize that this does not apply to this situation:
neither a="" nor b="" can generate an error so If a="" AND b="" Then is a
safe expression to use. If you were trying to evauate whether an object
variable was empty, Nothing, contained Null, or contained an empty string,
you would have to resort to nesting your boolean comparisons to avoid
errors. Using Select Case, however, no nesting is necessary. For example,
with recordsets, nested if statements are often used:

if not rs.eof then
if rs(0) is null then
elseif rs(0) ="" then
else
end if
end if

The nesting can get deep and is very often difficult to debug. Using Select
Case, however:

Select Case True
Case rs.eof
'code to handle empty recordset
Case rs(0) is Null
'code to handle case where the field contains null
Case rs(0) = ""
'code to handle case where the field contains ""
Case Else
'code which will only run when the field contains a value
End Case


HTH,
Bob Barrows
 
E

Evertjan.

Bob Barrows [MVP] wrote on 08 aug 2004 in
microsoft.public.inetserver.asp.general:
Using Select Case, however, no nesting is necessary. For example,
with recordsets, nested if statements are often used:

if not rs.eof then
if rs(0) is null then
elseif rs(0) ="" then
else
end if
end if

The nesting can get deep and is very often difficult to debug. Using
Select Case, however:

Select Case True
Case rs.eof
'code to handle empty recordset
Case rs(0) is Null
'code to handle case where the field contains null
Case rs(0) = ""
'code to handle case where the field contains ""
Case Else
'code which will only run when the field contains a value
End Case

Ah, the "reversed select case" method. ;-)

I think, Bob, that also here 'Select Case' is just a shorthand version if
the 'elsif', also here no nesting is necessary:

If rs.eof Then
'code to handle empty recordset
Elseif rs(0) is Null Then
'code to handle case where the field contains null
Elseif rs(0) = "" Then
'code to handle case where the field contains ""
Else
'code which will only run when the field contains a value
End If
 
R

Roland Hall

in message
: Seems the logic is not working..............

You're right. Why would anyone need to enter a form in two languages?

However...

dim strEnglish, strFrench, strLanguage
strEnglish = ""
strFrench = ""
strLanguage = "both"

strEnglish=Request.Form("strEnglish")
strFrench=Request.Form("strFrench")

if strEnglish <> "" and strFrench <> "" then
strLanguage = "both"
elseif strEnglish <> "" then
strLanguage = "English"
elseif strFrench <> "" then
strLanguage = "French"
else
' some other language
end if

or modify the form to accept English, French or both [English and French].
Then...

dim strLanguage
strLanguage = Response.Form("strLanguage")

select case strLanguage
case "both"
' English and French
case "English"
' English
case "French"
' French
case else
' Some other language
end select

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
B

Brad

Good evening Bob,

Now using the SELECT CASE (Reverse), and experiencing some issues:

My Code:

Select Case True
Case (strLink_e="" AND strLink_f="")
'ERROR message
Case (strLink_f="")
'User has entered an English URL string into Textbox
Case (strLink_e="")
'User has entered an French URL string into Textbox
Case Else
'User has entered into BOTH textboxs
End Select

Now, I have an Entry form , then a second form once the user has entered
into the first Entry form and clicked the SUBMIT button.

On all the Case Selects I see my DB working from the functionality of each
Case Select. However , I am experiencing a problem with the second form
page displaying itself for either just an English entriy OR just a French
entry...but when BOTH are entered.it works great (is displayed)

Any ideas why this would only work for BOTH , and not work for one OR the
other?

So, just to recap.

I have an Entry form:

Submit button

URL English TEXTBOX
URL French TEXTBOX


+++++++++++++++++++++++++++++++

Once the user enters his/her entry and clicks the Submit button,

Then I have another FORM that is called that will display the URL entered as
well as other info.

+++++++++++++++++++++++++++++++

However, this form seems to only reveal itself when the user has entered
into BOTH textboxes........if they enter into one OR the other.the
functionality that sits behind the chosen textbox entry works fine, yet the
second form does not display....

Do not know why??

Any ideas?

Thanks in advance,

~Brad
 
B

Bob Barrows [MVP]

I don't have enough information. I have no idea what "works great" and
"doesn't work" mean. I have no idea what code is running in each branch of
the select case statement.

It sounds as if you need to do some debugging to find out what your
variables contain at each step of the operation. Use alert() in your
cliinet-side code and response.write in your server-side code to figure
outwhat's going on.

Bob Barrows
 
B

Bã§TãRÐ

case info is usually sent vit the url in a querystring or in a hidden form variable. I'll do the querystring example for you but the hidden form field is just as easy.
the Url you are passing http://www.somedomain.com?lan=English

select case request.querystring("lan")

case "English"
do something here
case "French"
do something here
case else
do something here
end select

thats pretty much it - the case else statement is a default if nothing else is chosen

Hope that helps
- Bastard
 
B

Brad

After running m Debug code, I found that my problem was not within my SELECT
CASE. I was passing many varaibles and one of the varaibles, I changed the
name of it (as the IE: intNewID, where this would come after an INSERT to my
DB, returned from my Stored Procedure as an OUTPUT param.

The bottom line, the SELECT CASE or IF ELSEIF..... Both worked properlly, as
soon as I ran through using Response.Write ... Reponse.Flush, I found that
I was not making my intNewID available to the page, thus the reason why I
could not get the second FORM page to display itself.

Well all is well now,

Thanks to everyone for their input,

~Brad
;)
 
B

Brad

Thanks for your input,

Very much appraciated,

I figured out my problem, via debugging the page, my SLECT CASE , nor
original IF ELSEIF, were not where the problem arose. It was a variable
that was not being seen

Thanbks again,

~BRAD

Bã§TãRÐ said:
case info is usually sent vit the url in a querystring or in a hidden form
variable. I'll do the querystring example for you but the hidden form field
is just as easy.
the Url you are passing http://www.somedomain.com?lan=English

select case request.querystring("lan")

case "English"
do something here
case "French"
do something here
case else
do something here
end select

thats pretty much it - the case else statement is a default if nothing else is chosen

Hope that helps
- Bastard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top