472,110 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1.         dim variable
  2.  
  3.  
  4.     'clear_cache
  5.  
  6.  
  7. '=============='
  8. '== INCOMING =='
  9. '=============='
  10.  
  11.     action             = request("action")
  12.     sub_action        = request("sub_action")
  13.     product_id        = request("product_id")
  14.     cat_select         = request.form("cat_select")
  15.     cat_select         = replace(cat_select,"+"," ")
  16.         variable                  = request("brand_name")
  17.  
  18.  
And then again here. This one I couldnt quite grasp why he had placed it where he did, but it works.

Expand|Select|Wrap|Line Numbers
  1. <% if variable = "Engraving" then %>
  2. <% else %>
  3.  
next piece.
Expand|Select|Wrap|Line Numbers
  1. <% if variable = "Engraving" then %>
  2.  
  3.            <!--#include file="sci.asp"-->
  4.  
  5. <% else %>
  6.  
  7.  
And the last piece of where I see variable used.

Expand|Select|Wrap|Line Numbers
  1.         if variable <> "Engraving" then        
  2.            response.write "<font face=arial color=BLACK SIZE=2><b>"
  3.            response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
  4.                 end if
  5.  
  6.  
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

Expand|Select|Wrap|Line Numbers
  1. <% if if variable = "Engraving"
  2.  
  3.  else  if variable = "About Awareness" then
  4.  
  5.  else %>       
  6.  
next portion

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3. If if variable = "Engraving" Then
  4. <!--#include file = "sci.asp"-->
  5.  
  6. Else if variable = "About Awareness"
  7. <!--#include file = "aar.asp"-->
  8.  
  9. End If
  10. %>
  11.  
and then the last portion.

Expand|Select|Wrap|Line Numbers
  1.         if if variable <> "Engraving" then        
  2.            response.write "<font face=arial color=BLACK SIZE=2><b>"
  3.            response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
  4.                 else
  5.         if variable <> "About Awareness" then        
  6.            response.write "<font face=arial color=BLACK SIZE=2><b>"
  7.            response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
  8.                 end if
  9.  
  10.  
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
Mar 12 '07 #1
13 1699
hini
23
remove the "if if",
remove the first portion ,

replace the second one with:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. if variable = "Engraving" Then
  3. %>
  4. <!--#include file = "sci.asp"-->
  5. <%
  6.  
  7. Else 
  8.     if variable = "About Awareness" then
  9. %>
  10.     <!--#include file = "aar.asp"-->
  11. <%
  12.     End If
  13. end if
  14. %>
  15.  
  16.  

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:


Expand|Select|Wrap|Line Numbers
  1. if variable <> "Engraving" and variable <> "About Awareness" then        
  2.     response.write "<font face=arial color=BLACK SIZE=2><b>"
  3.     response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
  4. end if
  5.  
  6.  
  7.  
I hope this will work with u
Mar 13 '07 #2
remove the "if if",
remove the first portion ,

replace the second one with:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. if variable = "Engraving" Then
  3. %>
  4. <!--#include file = "sci.asp"-->
  5. <%
  6.  
  7. Else 
  8.     if variable = "About Awareness" then
  9. %>
  10.     <!--#include file = "aar.asp"-->
  11. <%
  12.     End If
  13. end if
  14. %>
  15.  
  16.  

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:


Expand|Select|Wrap|Line Numbers
  1. if variable <> "Engraving" and variable <> "About Awareness" then        
  2.     response.write "<font face=arial color=BLACK SIZE=2><b>"
  3.     response.write "<CENTER>VIEWING PAGE " & mypage & " OF " & maxpages & "</CENTER><br>"
  4. end if
  5.  
  6.  
  7.  
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.
Mar 13 '07 #3
jhardman
3,406 Expert 2GB
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
Expand|Select|Wrap|Line Numbers
  1. <% if variable = "Engraving" then %>
  2. <% else %>
is the same as
Expand|Select|Wrap|Line Numbers
  1. <% 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
Mar 13 '07 #4
This was in the second "fixed" code excerpt you gave, maybe just a typo. regardless, the original code was a bit silly. Saying
Expand|Select|Wrap|Line Numbers
  1. <% if variable = "Engraving" then %>
  2. <% else %>
is the same as
Expand|Select|Wrap|Line Numbers
  1. <% 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
Mar 13 '07 #5
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.
Mar 13 '07 #6
I would post all the code for the page, but I wouldn't want to flood the entire thread with so much code.
Mar 13 '07 #7
jhardman
3,406 Expert 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. if 'logical statement
  2.    'some line of code
  3.    'another hundred lines of code
  4. else
  5.    'some more code
  6. end if
  7.  
  8. do until x = 200
  9.    if action(x) = "death" then
  10.       response.write "you are dead meat<br>" & vbNewLine
  11.    else
  12.       response.write "<!-- action(" & x & "): " & action(x) " -->" & vbNewLine
  13.    end if
  14.    x = x + 1
  15. loop
  16.  
  17. sub clearThroat()
  18.    'line one
  19.    'line two
  20. 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
Mar 13 '07 #8
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?
Mar 15 '07 #9
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?
Mar 15 '07 #10
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?

Expand|Select|Wrap|Line Numbers
  1. <% if variable <> "Engraving" then %>
  2.  
Wouldnt I use something like,

Expand|Select|Wrap|Line Numbers
  1. <% if variable <> "Engraving" and variable <> "About Awareness"  then %>
  2.  
Mar 15 '07 #11
Scratch everything else guys. I was able to get all the code working, and actually learn a lot. Thank you very much everyone!
Mar 15 '07 #12
iam_clint
1,208 Expert 1GB
glad you learned something


good luck and come again i got to your post kinda late :)
Mar 15 '07 #13
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
Mar 15 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Jon | last post: by
9 posts views Thread by Alan | last post: by
7 posts views Thread by Klaus Johannes Rusch | last post: by
4 posts views Thread by Old Wolf | last post: by
4 posts views Thread by Rob Meade | last post: by
2 posts views Thread by tshad | last post: by
reply views Thread by rlwebbnafex | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.