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.



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

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
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.

  #2 (permalink)  
Old Aug 10th, 2004, 15:26
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
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.
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #3 (permalink)  
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.
  #4 (permalink)  
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.
  #5 (permalink)  
Old Aug 10th, 2004, 15:51
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
<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!
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #6 (permalink)  
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
  #7 (permalink)  
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.
  #8 (permalink)  
Old Aug 10th, 2004, 15:55
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
I think the presense of 'etc, etc, etc' means he could not be bothered to use C, D and E
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #9 (permalink)  
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..
  #10 (permalink)  
Old Aug 10th, 2004, 16:01
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
in this case, it aint numbers.... it is a string.
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #11 (permalink)  
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:
  #12 (permalink)  
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?
  #13 (permalink)  
Old Aug 10th, 2004, 16:15
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
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)
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #14 (permalink)  
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.
  #15 (permalink)  
Old Aug 10th, 2004, 16:37
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
I know...
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #16 (permalink)  
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
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 Introduce Yourself 4 Feb 8th, 2006 20:00
a simple question (I think) Colm Osiris Web Page Design 2 Feb 5th, 2006 09:17


All times are GMT. The time now is 04:34.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs 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 43