ASP variables?

Discussion in 'ASP General' started by thefunnel@aol.com, Jun 19, 2006.

  1. Guest

    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
    , Jun 19, 2006
    #1
    1. Advertising

  2. Turkbear Guest

    On 19 Jun 2006 08:01:54 -0700, wrote:

    >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..
    Turkbear, Jun 19, 2006
    #2
    1. Advertising

  3. Lee Carnell Guest

    Turkbear wrote:
    > On 19 Jun 2006 08:01:54 -0700, wrote:
    >
    >> 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..



    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.


    --
    --
    Lee Carnell
    Never enter a place you can't run out of.
    Lee Carnell, Jun 19, 2006
    #3
  4. <> wrote in message
    news:...
    > 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" />
    Anthony Jones, Jun 19, 2006
    #4
  5. Gazing into my crystal ball I observed "Anthony Jones"
    <> writing in
    news:eP#:

    >
    ><> wrote in message
    > news:...
    >> 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" />
    >


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

    --
    Adrienne Boswell at Home
    Arbpen Web Site Design Services
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
    Adrienne Boswell, Jun 20, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. avnrao
    Replies:
    0
    Views:
    3,362
    avnrao
    May 7, 2004
  2. Replies:
    1
    Views:
    931
  3. dwok
    Replies:
    7
    Views:
    697
    Hal Rosser
    Mar 4, 2005
  4. Replies:
    10
    Views:
    35,879
    jporter892
    Jun 6, 2011
  5. Replies:
    9
    Views:
    936
Loading...

Share This Page