ASP variables?

T

thefunnel

Hi,

I have the following ASP to display a certain image depending on a case
statement...

<%
Select Case (recordset("type"))
Case "type1"
Response.Write ("<img src=""type1.gif"" border=""0"">")
Case "type2"
Response.Write ("<img src=""type2.gif"" border=""0"">")
Case "type"
Response.Write ("<img src=""type3.gif"" border=""0"">")
End Select
%>

As the case section will be the same through out the document, and will
appear up to 30 times... Can I create some kind of "variable" at the
top and simply call it when required?

Many thanks,

Paul
 
T

Turkbear

Hi,

I have the following ASP to display a certain image depending on a case
statement...

<%
Select Case (recordset("type"))
Case "type1"
Response.Write ("<img src=""type1.gif"" border=""0"">")
Case "type2"
Response.Write ("<img src=""type2.gif"" border=""0"">")
Case "type"
Response.Write ("<img src=""type3.gif"" border=""0"">")
End Select
%>

As the case section will be the same through out the document, and will
appear up to 30 times... Can I create some kind of "variable" at the
top and simply call it when required?

Many thanks,

Paul

Perhaps yu can write it as a Subroutine and call it when needed..
 
L

Lee Carnell

Turkbear said:
Perhaps yu can write it as a Subroutine and call it when needed..


How about this....

Dim strImage
Select Case (recordset("type"))
Case "type1"
strImage = "<img src=type1.gif border=0 />"
Case "type2"
strImage = "<img src=type2.gif border=0 />"
Case "type"
strImage = "<img src=type3.gif border=0 />"
End Select

Then to display the image in the page just response.write strImage at the
appropraite point.
 
A

Anthony Jones

Hi,

I have the following ASP to display a certain image depending on a case
statement...

<%
Select Case (recordset("type"))
Case "type1"
Response.Write ("<img src=""type1.gif"" border=""0"">")
Case "type2"
Response.Write ("<img src=""type2.gif"" border=""0"">")
Case "type"
Response.Write ("<img src=""type3.gif"" border=""0"">")
End Select
%>

As the case section will be the same through out the document, and will
appear up to 30 times... Can I create some kind of "variable" at the
top and simply call it when required?

Many thanks,

Paul

What you need is a Function:-

Function GetTypeImg(rsType)

Select Case
Case "type1": GetTypeImg = "type1.gif"
Case "type2": GetTypeImg = "type2.gif"
Case "type3": GetTypeImg = "type3.gif"
End Select

End Function

At the point in the HTML where you want the img:-

<img src="<%=GetTypeImg(rst("type"))%>" border="0" />
 
A

Adrienne Boswell

What you need is a Function:-

Function GetTypeImg(rsType)

Select Case
Case "type1": GetTypeImg = "type1.gif"
Case "type2": GetTypeImg = "type2.gif"
Case "type3": GetTypeImg = "type3.gif"
End Select

End Function

At the point in the HTML where you want the img:-

<img src="<%=GetTypeImg(rst("type"))%>" border="0" />

I would remove border="0" to CSS [img {border:0}] and put in alt="".
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top