| | |
Exiting Select case statement
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2006
Posts: 14
Reputation:
Solved Threads: 0
So I'm coding a form in html and ASP and so far I have it working perfectly in terms of going from one page of the form to the next and shooting off an email at the end as verification of the form input.
What I've just inserted into the code now are some new form elements, namely a password and confirm password (this is for a member registration form).
What I want is for the page to proceed to the next part of the form if the password is the same as the confirm password, and to blast an error if the password values are not the same.
The select case statement that involves moving from one page to another (which worked until I inserted the bolded items) is this
I want to break out of the select statement once I reach the password mismatch, but the term "break" does nothing in ASP, so I'm wondering what is it's equivalent, or if there is even a way in the first place to exit from a select case statement.
Thanks so much beforehand for any and all advice. I hope nothing that I've mentioned so far is unclear or vague. Let me know if it is and I will try to clarify.
-LP
What I've just inserted into the code now are some new form elements, namely a password and confirm password (this is for a member registration form).
What I want is for the page to proceed to the next part of the form if the password is the same as the confirm password, and to blast an error if the password values are not the same.
The select case statement that involves moving from one page to another (which worked until I inserted the bolded items) is this
Select Case Request.Form("navigate")
Case "< Back"
intCurrentPage = intPreviousPage - 1
Case "Next >"
If Request.Form("cWP") = Request.Form("cWPconfirm") Then
intCurrentPage = intPreviousPage + 1
Else
AbortMessage = "Password mismatch, please re-enter and reconfirm password"
End If
Case Else
' Either it's our first run of the page and we're on page 1 or
' the form is complete and pages are unimportant because we're
' about to process our data!
intCurrentPage = 1
End SelectI want to break out of the select statement once I reach the password mismatch, but the term "break" does nothing in ASP, so I'm wondering what is it's equivalent, or if there is even a way in the first place to exit from a select case statement.
Thanks so much beforehand for any and all advice. I hope nothing that I've mentioned so far is unclear or vague. Let me know if it is and I will try to clarify.
-LP
•
•
Join Date: Jan 2009
Posts: 12
Reputation:
Solved Threads: 1
Hello,
Perhaps try a string Comparison to see if the values are the same, and I am not sure what the brackets before your Back case and after your Next case are for. Also if you are moving to a different page if the passwords match you might want to add Response.Redirect "Different_Page.asp" in your if statment to exit the case and page. Depending on the server you are on you may also want to do a conversion of the two form elements you are comparing "CStr"
I hope I understood what it is you are trying to do.
Perhaps try a string Comparison to see if the values are the same, and I am not sure what the brackets before your Back case and after your Next case are for. Also if you are moving to a different page if the passwords match you might want to add Response.Redirect "Different_Page.asp" in your if statment to exit the case and page. Depending on the server you are on you may also want to do a conversion of the two form elements you are comparing "CStr"
I hope I understood what it is you are trying to do.
asp Syntax (Toggle Plain Text)
Select Case Request.Form("navigate") Case "Back" intCurrentPage = intPreviousPage - 1 Case "Next" If StrComp(Request.Form("cWP"),Request.Form("cWPconfirm"))=0 Then intCurrentPage = intPreviousPage + 1 Response.Redirect "Different_Page.asp" Else AbortMessage = "Password mismatch, please re-enter and reconfirm password" End If Case Else intCurrentPage = 1 End Select
•
•
Join Date: Sep 2006
Posts: 14
Reputation:
Solved Threads: 0
Hi CTS,
Thank you for the advice on the structure of the code. A couple of clarifications for you:
1. I'm staying within the same page and using select case statements to change the form based on the "current page" that you are on. Basically it's trying to mimic a multi-page form without ever leaving the first page.
2. The carats/brackets after Next and Back are just the values for the submit buttons on the bottom of the form. Aka Next > and < Back. They both have the name "navigate" and so it's basically trying to figure out which of the 2 buttons was pushed and what to do based on what button was pushed.
I realized after some more exhaustive research that there is no break out of a select case statement, except to do
I have changed my code now to use StrComp to compare the 2 passwords, as it seems more clean and efficient.
Thank you for the advice on the structure of the code. A couple of clarifications for you:
1. I'm staying within the same page and using select case statements to change the form based on the "current page" that you are on. Basically it's trying to mimic a multi-page form without ever leaving the first page.
2. The carats/brackets after Next and Back are just the values for the submit buttons on the bottom of the form. Aka Next > and < Back. They both have the name "navigate" and so it's basically trying to figure out which of the 2 buttons was pushed and what to do based on what button was pushed.
I realized after some more exhaustive research that there is no break out of a select case statement, except to do
asp Syntax (Toggle Plain Text)
For i = 0 to 1 Select Case Request.Form("Navigate") Case "< Back" intCurrentPage = intPreviousPage - 1 Case "Next >" If Request.Form("cPW") = Request.Form("cPWconfirm) Then intCurrentPage = intPreviousPage + 1 Else AbortMessage = "Password Mismatch, please try again" Exit For End If ...
I have changed my code now to use StrComp to compare the 2 passwords, as it seems more clean and efficient.
•
•
Join Date: Jan 2009
Posts: 12
Reputation:
Solved Threads: 1
Hello LurkerPatrol,
Ok now I think I have a better idea of what you are trying to do.
First thing, add a hidden value to your initial form.
Then at the top of your page under your dim statments check for the hidden value. If the value is null it will fall through and run a sub that dispays the initial page. if the hidden value is true it will run the nested if statments.
I am not sure of the structure of your page but if the comparison for password is true the code will call a sub (SComplete) that displays the final result. If there is an error in the password it will call a sub (SLoginform) that will show the password form and allow the AbortMessage to be shown. Now if Request.Form("navigate") does not = "Next" it will call the sub (SBackform) that the user requested by hitting the "Back" button. As I said I am not sure on your page setup the back button may bring up the same form as the password form in which case you would only need to call the one sub (SLoginForm) for each instance.
I hope this helps out.
Ok now I think I have a better idea of what you are trying to do.
First thing, add a hidden value to your initial form.
asp Syntax (Toggle Plain Text)
Response.Write "<input type='hidden' name='ispostback' value='1'>" Response.Write "<input type='navigate' value='< Back' name='Back'>" Response.Write "<input type='navigate' value='Next >' name='Next'>"
Then at the top of your page under your dim statments check for the hidden value. If the value is null it will fall through and run a sub that dispays the initial page. if the hidden value is true it will run the nested if statments.
asp Syntax (Toggle Plain Text)
First = len(Request.Form ("IsPostBack")) < 1 If First Then If Request.Form("navigate") = "Next" Then If StrComp(Request.Form("cWP"),Request.Form("cWPconfirm"))=0 Then Call SComplete Else AbortMessage = "Password mismatch" Call SLoginForm End If Else Call SBackForm End if Else Call SForm End if
I hope this helps out.
![]() |
Similar Threads
- Select case trouble (ASP.NET)
- Reputed number problem switch case statement (VB.NET)
- Linking Select Case with Buttons (VB.NET)
- Select Case Problem (VB.NET)
- how do I nest a CASE statement in an INNER JOIN (Oracle)
- Problem w/ LIMIT in CASE statement (MySQL)
- Is Select Case statement case sensitive in VB6? (Visual Basic 4 / 5 / 6)
- Switch Case Statement (Java)
- switch/case statement (C++)
Other Threads in the ASP Forum
- Previous Thread: How i Can connect Sql Server with ASP
- Next Thread: quick asp question
Views: 890 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for ASP
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection calendar changeable connection current database databaseconnection diagnostics dreamweaver excel fso html iis microsoft msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile query record searchbox selectoption server single specfic sqlserver sqlserverconnection toolkit update web webserver windows7





