943,865 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 1520
  • ASP RSS
Aug 12th, 2009
0

Exiting Select case statement

Expand Post »
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

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 Select

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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LurkerPatrol is offline Offline
14 posts
since Sep 2006
Aug 13th, 2009
0

Re: Exiting Select case statement

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.

asp Syntax (Toggle Plain Text)
  1. Select Case Request.Form("navigate")
  2. Case "Back"
  3. intCurrentPage = intPreviousPage - 1
  4. Case "Next"
  5. If StrComp(Request.Form("cWP"),Request.Form("cWPconfirm"))=0 Then
  6. intCurrentPage = intPreviousPage + 1
  7. Response.Redirect "Different_Page.asp"
  8. Else
  9. AbortMessage = "Password mismatch, please re-enter and reconfirm password"
  10. End If
  11. Case Else
  12. intCurrentPage = 1
  13. End Select
Reputation Points: 10
Solved Threads: 1
Newbie Poster
closetosane is offline Offline
12 posts
since Jan 2009
Aug 13th, 2009
0

Re: Exiting Select case statement

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

asp Syntax (Toggle Plain Text)
  1. For i = 0 to 1
  2. Select Case Request.Form("Navigate")
  3. Case "< Back"
  4. intCurrentPage = intPreviousPage - 1
  5. Case "Next >"
  6. If Request.Form("cPW") = Request.Form("cPWconfirm) Then
  7. intCurrentPage = intPreviousPage + 1
  8. Else
  9. AbortMessage = "Password Mismatch, please try again"
  10. Exit For
  11. End If
  12. ...
  13.  

I have changed my code now to use StrComp to compare the 2 passwords, as it seems more clean and efficient.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LurkerPatrol is offline Offline
14 posts
since Sep 2006
Aug 13th, 2009
0

Re: Exiting Select case statement

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.

asp Syntax (Toggle Plain Text)
  1. Response.Write "<input type='hidden' name='ispostback' value='1'>"
  2. Response.Write "<input type='navigate' value='< Back' name='Back'>"
  3. 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)
  1. First = len(Request.Form ("IsPostBack")) < 1
  2. If First Then
  3. If Request.Form("navigate") = "Next" Then
  4. If StrComp(Request.Form("cWP"),Request.Form("cWPconfirm"))=0 Then
  5. Call SComplete
  6. Else
  7. AbortMessage = "Password mismatch"
  8. Call SLoginForm
  9. End If
  10. Else
  11. Call SBackForm
  12. End if
  13. Else
  14. Call SForm
  15. End if
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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
closetosane is offline Offline
12 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Problem Linking in aspx file with asp file
Next Thread in ASP Forum Timeline: quick asp question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC