Link to home
Start Free TrialLog in
Avatar of garethtnash
garethtnashFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Nested VBScript If Statement

Hello Experts,

Happy New Year :)

Grateful if you could look at the attached script, and tell me the best way to write it, I'm looking for one outcome..

only one of the following parameters is sent at any time -

"k"
"j"
"c"
"e"
"s"

the "jobs-in" parameter may or not be sent in addition to the main parameter sent..

Please advise..

Many thanks
<% if request("jobs-in") = "" then
if request("k") <> "" then request("k") jobs 
Else
if request("j") <> "" then request("j") jobs
Else
if request("c") <> "" then request("c") jobs
Else 
if request("e") <> "" then request("e") jobs
Else
if request("s") <> "" then request("s") jobs
End if
%>
<%if request("jobs-in") <> "" then 
if request("k") <> "" then request("k") jobs in request("jobs-in")
Else
if request("j") <> "" then request("j") jobs in request("jobs-in")
Else
if request("c") <> "" then request("c") jobs in request("jobs-in")
Else 
if request("e") <> "" then request("e") jobs in request("jobs-in")
Else
if request("s") <> "" then request("s") jobs in request("jobs-in")
End if
%>
<%if request("jobs-in") <> "" then 
if request("k") = "" then jobs in request("jobs-in")
Else
if request("j") = "" then jobs in request("jobs-in")
Else
if request("c") = "" then jobs in request("jobs-in")
Else 
if request("e") = "" then jobs in request("jobs-in")
Else
if request("s") = "" then jobs in request("jobs-in")
End if
%>

Open in new window

Avatar of jkurzner
jkurzner

What is it you are trying to do.  I think a Select Case statement might be better, but it's a little hard to determine what you are doing.  Are you retrieving the jobs-in variable from a form or a query string? What are the k,j,c,e,s variables?  It's a bit confusing.
Avatar of garethtnash

ASKER

I'm trying to write a response based upon what is sent, the following could be sent -

k=xx&jobs-in=yy
k=xx
jobs-in=yy

(k could be the name parameter for k,j,c.e or s)

this wouldn't get sent

k=xx&e=zzz&jobs-in=yy
k=xx&e=zz

Hope that helps?

thanks
The first thing to notice is you need "elseif" in stead of "else if".
As clarification i added the the correct code.

Think might be the only problem, but i don't entirely understand what you are trying to do. If this still does not work could you give, besides the example input, also an example output?
<% if request("jobs-in") = "" then
if request("k") <> "" then request("k") jobs 
Elseif request("j") <> "" then request("j") jobs
Elseif request("c") <> "" then request("c") jobs
Elseif request("e") <> "" then request("e") jobs
Elseif request("s") <> "" then request("s") jobs
End if
%>
<%if request("jobs-in") <> "" then 
if request("k") <> "" then request("k") jobs in request("jobs-in")
Elseif request("j") <> "" then request("j") jobs in request("jobs-in")
Elseif request("c") <> "" then request("c") jobs in request("jobs-in")
Elseif request("e") <> "" then request("e") jobs in request("jobs-in")
Elseif request("s") <> "" then request("s") jobs in request("jobs-in")
End if
%>
<%if request("jobs-in") <> "" then 
if request("k") = "" then jobs in request("jobs-in")
Elseif request("j") = "" then jobs in request("jobs-in")
Elseif request("c") = "" then jobs in request("jobs-in")
Elseif request("e") = "" then jobs in request("jobs-in")
Elseif request("s") = "" then jobs in request("jobs-in")
End if
%>

Open in new window

I still think you need to be a little more clear about the query string.  Will the xx value always be the same (www.test.com?k=1&jobs-in=yy or www.test.com?e=1&jobs

A better example of actual data might be helpful
Thanks Iandian,

i tried your version, and got an error, so i changed the code slightly (below)

But io'm still getting the error message --

Microsoft VBScript compilation error '800a0400'

Expected statement

/jobs.asp, line 462

& request("k") & " jobs"

thank you
<% if request("jobs-in") = "" then
if request("k") <> "" then 
& request("k") & " jobs" 
Elseif request("j") <> "" then 
& request("j") & " jobs"
Elseif request("c") <> "" then 
& request("c") & " jobs"
Elseif request("e") <> "" then 
& request("e") & " jobs"
Elseif request("s") <> "" then 
& request("s") & " jobs"
End if
%>
<%if request("jobs-in") <> "" then 
if request("k") <> "" then 
& request("k") & " jobs in " & request("jobs-in")
Elseif request("j") <> "" then 
& request("j") & " jobs in " & request("jobs-in")
Elseif request("c") <> "" then 
& request("c") & " jobs in " & request("jobs-in")
Elseif request("e") <> "" then 
& request("e") & " jobs in " & request("jobs-in")
Elseif request("s") <> "" then 
& request("s") & " jobs in " & request("jobs-in")
End if
%>
<%if request("jobs-in") <> "" then 
if request("k") = "" then 
"jobs in " & request("jobs-in")
Elseif request("j") = "" then 
"jobs in " & request("jobs-in")
Elseif request("c") = "" then 
"jobs in " & request("jobs-in")
Elseif request("e") = "" then 
"jobs in " & request("jobs-in")
Elseif request("s") = "" then 
"jobs in " & request("jobs-in")
End if
%>

Open in new window

Ah, i see i forgot some end if's

Try this.
<% if request("jobs-in") = "" then
	if request("k") <> "" then request("k") jobs 
	Elseif request("j") <> "" then request("j") jobs
	Elseif request("c") <> "" then request("c") jobs
	Elseif request("e") <> "" then request("e") jobs
	Elseif request("s") <> "" then request("s") jobs
	End if
End if
%>
<%if request("jobs-in") <> "" then 
	if request("k") <> "" then request("k") jobs in request("jobs-in")
	Elseif request("j") <> "" then request("j") jobs in request("jobs-in")
	Elseif request("c") <> "" then request("c") jobs in request("jobs-in")
	Elseif request("e") <> "" then request("e") jobs in request("jobs-in")
	Elseif request("s") <> "" then request("s") jobs in request("jobs-in")
	End if
End if
%>
<%if request("jobs-in") <> "" then 
	if request("k") = "" then jobs in request("jobs-in")
	Elseif request("j") = "" then jobs in request("jobs-in")
	Elseif request("c") = "" then jobs in request("jobs-in")
	Elseif request("e") = "" then jobs in request("jobs-in")
	Elseif request("s") = "" then jobs in request("jobs-in")
	End if
End if
%>

Open in new window

Thanks,

Have managed to get the first part working, by using response.write like so -

<% if request("jobs-in") = "" then
if request("k") <> "" then
response.write(request("k")) & " jobs"
Elseif request("j") <> "" then
response.write(request("j")) & " jobs"
Elseif request("c") <> "" then
response.write(request("c")) & " jobs"
Elseif request("e") <> "" then
response.write(request("e")) & " jobs"
Elseif request("s") <> "" then
response.write(request("s")) & " jobs"
End if
End if
%>

Now just need to establish how to apply this tothe two other sections...

Please advise.

thank you
SOLUTION
Avatar of iandian
iandian
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
looks good, like your logic, but

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/jobs.asp, line 710

Dim jobsString As String


thanks in advance
hmm, remove the "As String" i think
sorry, programming in too many languages lately :) gets confusing
Thats fantastic, thank you,. one last question, any way of capitalising the first letter of each of the parameters that is written?

Many thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Big Thank you :D