ASP variables?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thefunnel@aol.com

    ASP variables?

    Hi,

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

    <%
    Select Case (recordset("typ e"))
    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

  • Turkbear

    #2
    Re: ASP variables?

    On 19 Jun 2006 08:01:54 -0700, thefunnel@aol.c om wrote:
    [color=blue]
    >Hi,
    >
    >I have the following ASP to display a certain image depending on a case
    >statement...
    >
    ><%
    >Select Case (recordset("typ e"))
    > 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[/color]

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


    Comment

    • sashi
      Recognized Expert Top Contributor
      • Jun 2006
      • 1749

      #3
      Hi Paul,

      emm.. i think using case is to simply coding method.. emm.. let me see.. u want to further simplify it eh.. emm.. why not try using while loop.. well.. since your graphic file name ends up with an integer.. "typeN.gif" .. you can use while loop with an increment counter method.. u know.. some thing like

      <%
      while not nType
      ..
      nType = nType = 1 untill nType = 30 .. this is just to give you some basic idea..
      ..
      loop
      %>

      try it.. change the code n post the changes.. will help to check it for you.. good luck..

      you know what Paul.. i hate to write program for ppl.. but, instead i love to help them to troubleshoot their code.. :) so.. give it a try n come back later.. good luck buddy..

      Comment

      • Lee Carnell

        #4
        Re: ASP variables?

        Turkbear wrote:[color=blue]
        > On 19 Jun 2006 08:01:54 -0700, thefunnel@aol.c om wrote:
        >[color=green]
        >> Hi,
        >>
        >> I have the following ASP to display a certain image depending on a
        >> case statement...
        >>
        >> <%
        >> Select Case (recordset("typ e"))
        >> 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[/color]
        >
        > Perhaps yu can write it as a Subroutine and call it when needed..[/color]


        How about this....

        Dim strImage
        Select Case (recordset("typ e"))
        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.


        Comment

        • Anthony Jones

          #5
          Re: ASP variables?


          <thefunnel@aol. com> wrote in message
          news:1150729314 .360868.124140@ f6g2000cwb.goog legroups.com...[color=blue]
          > Hi,
          >
          > I have the following ASP to display a certain image depending on a case
          > statement...
          >
          > <%
          > Select Case (recordset("typ e"))
          > 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
          >[/color]

          What you need is a Function:-

          Function GetTypeImg(rsTy pe)

          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="<%=GetType Img(rst("type") )%>" border="0" />




          Comment

          • Adrienne Boswell

            #6
            Re: ASP variables?

            Gazing into my crystal ball I observed "Anthony Jones"
            <Ant@yadayadaya da.com> writing in
            news:eP#gMt7kGH A.1320@TK2MSFTN GP04.phx.gbl:
            [color=blue]
            >
            ><thefunnel@aol .com> wrote in message
            > news:1150729314 .360868.124140@ f6g2000cwb.goog legroups.com...[color=green]
            >> Hi,
            >>
            >> I have the following ASP to display a certain image depending on a
            >> case statement...
            >>
            >> <%
            >> Select Case (recordset("typ e"))
            >> 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
            >>[/color]
            >
            > What you need is a Function:-
            >
            > Function GetTypeImg(rsTy pe)
            >
            > 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="<%=GetType Img(rst("type") )%>" border="0" />
            >[/color]

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

            --
            Adrienne Boswell at Home
            Arbpen Web Site Design Services
            Arbpen Consulting will help you harness valuable insights and translate them into tangible results by merging data and strategy.

            Please respond to the group so others can share

            Comment

            Working...