Reusing a variable in .ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GGawaran
    New Member
    • Mar 2007
    • 24

    Reusing a variable in .ASP

    First off, Hi everyone new to .asp and am trying to self teach myself. Im trying to figure out what exactly im doing wrong, or maybe what I think I can do, I really cant.

    The Idea.
    -------------------

    On our website, we have several pieces of code we entered in so in the event that when you click on the category section, and "Engraving" was selected, it would load an include file and show our engraving options, etc. Well, I figured, we could use that same code, add some else statements we could have it when they clicked on "About Awareness" then the same thing would happen and include a different include file and have the new content show up. I might not be wording my words very well so ill show you the pieces of code and perhaps enlighten me on what im doing wrong.

    There is other dims, but this is the one i am mentioning to the above. This is the first portion of the variable code. (I didnt code this, as it was done by an ex employee.) Im posting what was done first, and then posting what changes i made thinking it would work that way.

    Code:
            dim variable
            
    	
    	'clear_cache
    
    
    '=============='
    '== INCOMING =='
    '=============='
    
    	action 			= request("action")
    	sub_action		= request("sub_action")
    	product_id		= request("product_id")
    	cat_select 		= request.form("cat_select")
    	cat_select 		= replace(cat_select,"+"," ")
            variable                  = request("brand_name")
    And then again here. This one I couldnt quite grasp why he had placed it where he did, but it works.

    Code:
    <% if variable = "Engraving" then %>
    <% else %>
    next piece.
    Code:
    <% if variable = "Engraving" then %>
               
               <!--#include file="sci.asp"-->
              
    <% else %>
    And the last piece of where I see variable used.

    Code:
    		if variable <> "Engraving" then		
    		   response.write "<font face=arial color=BLACK SIZE=2><b>"
    		   response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
                    end if
    I took Comp Sci I and II during highschool, so i have a rough understanding, so with what i thought would work I did the following

    I didnt change anything in the first portion but on the second portion I did

    Code:
    <% if if variable = "Engraving"
    
     else  if variable = "About Awareness" then
    
     else %>
    next portion

    Code:
    <%
    If if variable = "Engraving" Then
    <!--#include file = "sci.asp"-->
    
    Else if variable = "About Awareness"
    <!--#include file = "aar.asp"-->
    
    End If
    %>
    and then the last portion.

    Code:
    		if if variable <> "Engraving" then		
    		   response.write "<font face=arial color=BLACK SIZE=2><b>"
    		   response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
                    else
    		if variable <> "About Awareness" then		
    		   response.write "<font face=arial color=BLACK SIZE=2><b>"
    		   response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
                    end if
    I may have totally slaughtered some of this code, and may have taken more then I can chew, but im working hard to try to get it to work.

    Any recommendations would be appreciated.

    Thank you very much,

    Gregory Gawaran
  • hini
    New Member
    • Mar 2007
    • 23

    #2
    remove the "if if",
    remove the first portion ,

    replace the second one with:
    Code:
    <%
    if variable = "Engraving" Then
    %>
    <!--#include file = "sci.asp"-->
    <%
    
    Else 
    	if variable = "About Awareness" then
    %>
    	<!--#include file = "aar.asp"-->
    <%
    	End If
    end if
    %>

    the last portion is logically wrong,
    if you don't want to display the sentence
    "VIEWING PAGE...." in both cases when the users chooses either "about awareness" or "engraving" , u must use the following:


    Code:
    if variable <> "Engraving" and variable <> "About Awareness" then		
    	response.write "<font face=arial color=BLACK SIZE=2><b>"
    	response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
    end if
    I hope this will work with u

    Comment

    • GGawaran
      New Member
      • Mar 2007
      • 24

      #3
      Originally posted by hini
      remove the "if if",
      remove the first portion ,

      replace the second one with:
      Code:
      <%
      if variable = "Engraving" Then
      %>
      <!--#include file = "sci.asp"-->
      <%
      
      Else 
      	if variable = "About Awareness" then
      %>
      	<!--#include file = "aar.asp"-->
      <%
      	End If
      end if
      %>

      the last portion is logically wrong,
      if you don't want to display the sentence
      "VIEWING PAGE...." in both cases when the users chooses either "about awareness" or "engraving" , u must use the following:


      Code:
      if variable <> "Engraving" and variable <> "About Awareness" then		
      	response.write "<font face=arial color=BLACK SIZE=2><b>"
      	response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
      end if
      I hope this will work with u
      Thanks, im in the process of trying it out right now. And I understand what I was doing wrong haha. however, I am wondering about what you meant by the "if if" statment and which first portion do I remove.

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Originally posted by GGawaran
        I am wondering about what you meant by the "if if" statment and which first portion do I remove.
        This was in the second "fixed" code excerpt you gave, maybe just a typo. regardless, the original code was a bit silly. Saying
        Code:
        <% if variable = "Engraving" then %>
        <% else %>
        is the same as
        Code:
        <% if variable <> "Engraving" then %>
        only sloppier. Having said that, I admit that I have done the same... Perhaps the original coder was planning to put some code in the intervening space.

        Jared

        Comment

        • GGawaran
          New Member
          • Mar 2007
          • 24

          #5
          Originally posted by jhardman
          This was in the second "fixed" code excerpt you gave, maybe just a typo. regardless, the original code was a bit silly. Saying
          Code:
          <% if variable = "Engraving" then %>
          <% else %>
          is the same as
          Code:
          <% if variable <> "Engraving" then %>
          only sloppier. Having said that, I admit that I have done the same... Perhaps the original coder was planning to put some code in the intervening space.

          Jared
          Thanks Jared for the clerification. I have the new code in, and I just need to test it out. I will let you guys know how it goes =).

          Thanks again,

          Greg

          Comment

          • GGawaran
            New Member
            • Mar 2007
            • 24

            #6
            Well, I got it in, and I tried, it, but I got the following error.

            Microsoft VBScript compilation error '800a0400'

            Expected statement

            /pages/pages_shop.asp, line 416

            end if
            ^

            checking the code on line 416 is <% end if %>

            As stated in my first post, im new to ASP, so im not exactly sure what it is thats missing.

            Comment

            • GGawaran
              New Member
              • Mar 2007
              • 24

              #7
              I would post all the code for the page, but I wouldn't want to flood the entire thread with so much code.

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #8
                Originally posted by GGawaran
                Microsoft VBScript compilation error '800a0400'

                Expected statement

                /pages/pages_shop.asp, line 416

                end if
                ^
                This means it found an "end if" but there doesn't seem to be a corresponding "if"

                This is where indenting the code really helps out. Go back over your code and wherever you are waiting for some line which ends something you started, indent the code by one tab:
                Code:
                if 'logical statement
                   'some line of code
                   'another hundred lines of code
                else
                   'some more code
                end if
                
                do until x = 200
                   if action(x) = "death" then
                      response.write "you are dead meat<br>" & vbNewLine
                   else
                      response.write "<!-- action(" & x & "): " & action(x) " -->" & vbNewLine
                   end if
                   x = x + 1
                loop
                
                sub clearThroat()
                   'line one
                   'line two
                end sub
                this is hard to do when someone else wrote the page originally, but is the most straight-forward way to find this type of problem.

                Jared

                Comment

                • GGawaran
                  New Member
                  • Mar 2007
                  • 24

                  #9
                  Alrighty, i'm going through the process right now, and so far so good, I figured I should go ahead and indent the entire page so itll be easier for me in the future. However, the problem im looking for is something I created with the new code that I put in correct?

                  Comment

                  • GGawaran
                    New Member
                    • Mar 2007
                    • 24

                    #10
                    I would have just edited my last post, but 5 minutes had passed. I wanted to clarify a piece of code or rather, ask what the difference is. Im familiar with seeing if and end if statements. But when I look through this code, I see a lot of <% end if %> is that a end if statement for server pages?

                    Comment

                    • GGawaran
                      New Member
                      • Mar 2007
                      • 24

                      #11
                      Also, since I added the "About Awareness" information on the other portions of code, wouldn't I need to add something about awareness in this portion of code as well?

                      Code:
                      <% if variable <> "Engraving" then %>
                      Wouldnt I use something like,

                      Code:
                      <% if variable <> "Engraving" and variable <> "About Awareness"  then %>

                      Comment

                      • GGawaran
                        New Member
                        • Mar 2007
                        • 24

                        #12
                        Scratch everything else guys. I was able to get all the code working, and actually learn a lot. Thank you very much everyone!

                        Comment

                        • iam_clint
                          Recognized Expert Top Contributor
                          • Jul 2006
                          • 1207

                          #13
                          glad you learned something


                          good luck and come again i got to your post kinda late :)

                          Comment

                          • GGawaran
                            New Member
                            • Mar 2007
                            • 24

                            #14
                            thanks clint, this has to be one of the best sites I have found. I am new with asp, and because of jhardman, hini and any others i might have forgotten, found out my code was missing some things, and I wasnt placing <% %> in the right places. But after figuring that out, I was able to execute other changes that needed to be done without error.

                            Will definitelty be back since im still learning, but will most definitely stay on board and help others with what I learn.

                            Gregory

                            Comment

                            Working...