Simple if statement question.

This is a discussion on "Simple if statement question." within the Classic ASP section. This forum, and the thread "Simple if statement question. are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
Old Aug 10th, 2004, 13:41
New Member
Join Date: Aug 2004
Location: United Kingdom
Age: 29
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Simple if statement question.

Hello everybody, I have only just started using ASP so if this question seems pretty obvious to you guys then bare with me.

Basically I have one page with a form on it and two dropdown menus. I want to take the result from both drop down boxes and on the next page use these differing answers to generate a quote. However I don't know the proper syntax of how to do this (although I'm pretty sure an If then else statement would suffice). I have put all the code on the second page and it is just pulling through the data from the drop down menus on the first page. Here is my code:

//Type and Level are the names of the drop down menus on the previous page

strType = request.form("Type")
strLevel = request.form("Level")
myQuote = "0"

if (strType="Type A")&&(strLevel="Level 1") then myQuote = "8.60"

else if (strType="Type A")&&(strLevel="Level 2") then myQuote = "10.20"

etc etc etc

else myQuote = "2"

end if

Any help would be much appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Aug 10th, 2004, 15:26
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
It would make more sense to use a nested Select statement:-
Code: Select all
<%
strType = request.form("Type")
strLevel = request.form("Level")

Select Case StrType
    Case "Type A"
        Select Case StrLevel
            Case "Level 1" myQuote = "8.60"
            Case "Level 2" myquote = "10.20"
        End Select
    Case "Type B"
        Select Case StrLevel
            Case "Level 1" myQuote = "18.60"
            Case "Level 2" myquote = "110.20"
        End Select
    Case Else myQuote = "2"
End Select
%>
I'm sure you get the idea.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Aug 10th, 2004, 15:46
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
I'd do it something like this...
Code: Select all
<%
dim tpe
dim lvl
dim tot

If request.form("Type") = "Type A" Then 
  tpe = 4.60
Else 
  tpe = 5.60
End If
If request.form("Level") = "Level 1" Then
  lvl = 4.00
Else
  lvl = 5.60
End If

tot = tpe + lvl

Response.Write(tot)
%>
For an example of how this code works... See it here.. http://wwwhaeglodesigns.com/hths/tester.asp

Lol, sorry for being lazy, I put in text boxes, so just type in the different combinations to see your result.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Aug 10th, 2004, 15:48
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Rob.. why would you use a select Case statement here? Its a yes or no question... nothing worth going through all of that for.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Aug 10th, 2004, 15:51
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
<blockquote id="quote" class="ffs">quote:<hr height="1" noshade="noshade" id="quote" />Its a yes or no question... nothing worth going through all of that for.<hr height="1" noshade="noshade" id="quote" /></blockquote id="quote">
Funny Court Jester.... I cannot see one single mention of the fact it is a yes / no question!!
The presence of 'etc, etc, etc' would suggest it is not.

Besides, the Select Case statement is far easier to read, and debug, as any ASP developer here will tell ya!
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #6  
Old Aug 10th, 2004, 15:52
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
...and its faster
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #7  
Old Aug 10th, 2004, 15:53
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Well.. Its an A or its going to be B. So If A was Yes, then be would be No.... I figured you had some good reason why you used that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #8  
Old Aug 10th, 2004, 15:55
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
I think the presense of 'etc, etc, etc' means he could not be bothered to use C, D and E
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #9  
Old Aug 10th, 2004, 15:59
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Ahh and there it is ladies and gents... lol

ok... but do you use quotes around the numbers in your code?? I thought quotes made them where they don't add but attatch them to the end of the previous number..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #10  
Old Aug 10th, 2004, 16:01
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
in this case, it aint numbers.... it is a string.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #11  
Old Aug 10th, 2004, 16:03
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Ahh, ok. Thanks for explaining it to me . That's very nice their Robby :wink:
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #12  
Old Aug 10th, 2004, 16:11
New Member
Join Date: Aug 2004
Location: United Kingdom
Age: 29
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Yes you are right Rob, I was just being lazy and couldn't be bothered to type out the whole code. I have Type A to Type D in the actual code.

I have tried your nested select statement but all I get is an HTTP 500 - Internal server error. My code now reads like this:
Code: Select all
<%
strType = request.form("Type")
strLevel = request.form("Level")

Quote = "0"

Select Case strType
    Case "Type A"
        Select Case strLevel
            Case "Level 1" Quote = "5.57"
            Case "Level 2" Quote = "7.88"
        End Select

Select Case strType
    Case "Type B"
        Select Case strLevel
            Case "Level 1" Quote = "10.45"
            Case "Level 2" Quote = "14.18"
        End Select

Select Case strType
    Case "Type C"
        Select Case strLevel
            Case "Level 1" Quote = "6.62"
            Case "Level 2" Quote = "9.35"
        End Select

Select Case strType
    Case "Type D"
        Select Case strLevel
            Case "Level 1" Quote = "11.50"
            Case "Level 2" Quote = "15.65"
        End Select

    Case Else Quote = "2"
End Select
%>

Should it matter whereabouts on the page I put this code?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #13  
Old Aug 10th, 2004, 16:15
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
not quite right.... use this:-
Code: Select all
<%
strType = request.form("Type")
strLevel = request.form("Level")

Quote = "0"

Select Case strType
    Case "Type A"
        Select Case strLevel
            Case "Level 1" Quote = "5.57"
            Case "Level 2" Quote = "7.88"
        End Select

    Case "Type B"
        Select Case strLevel
            Case "Level 1" Quote = "10.45"
            Case "Level 2" Quote = "14.18"
        End Select

    Case "Type C"
        Select Case strLevel
            Case "Level 1" Quote = "6.62"
            Case "Level 2" Quote = "9.35"
        End Select

    Case "Type D"
        Select Case strLevel
            Case "Level 1" Quote = "11.50"
            Case "Level 2" Quote = "15.65"
        End Select

    Case Else Quote = "2"
End Select
%>
Can you please remember to surround pasted code with [ code ] [ /code ] tags? (remove spaces)
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #14  
Old Aug 10th, 2004, 16:31
New Member
Join Date: Aug 2004
Location: United Kingdom
Age: 29
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Cheers Rob, you're a star.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #15  
Old Aug 10th, 2004, 16:37
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
I know...
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #16  
Old Aug 10th, 2004, 18:08
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
lol
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
simple, statement, question

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
hopefully a simple question newoptical Hosting & Domains 9 Sep 21st, 2007 22:02
simple question Daniel Web Page Design 29 Feb 6th, 2007 17:23
a simple question (I think) Colm Osiris Web Page Design 2 Feb 5th, 2006 09:17


All times are GMT. The time now is 21:08.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42