VB code in form

  • Thread starter Thread starter lpjennifer
  • Start date Start date
L

lpjennifer

This is my 1st time embedding code in a form and I'm not
quite sure where to put the code (the "IF" statements as
well as my "SELECT" statement).. When the user hits
the "submit" I would like the page to be re-directed to a
new page dependent on it's case. Any help would be
greatly aprreciated. thanks! Here it is:

Dim numcorr
numcorr = 0
if request("answer1") = "1C" then numcorr = numcorr + 1
if request("answer2") = "1E" then numcorr = numcorr + 1
if request("answer3") = "1C" then numcorr = numcorr + 1
if request("answer4") = "1E" then numcorr = numcorr + 1
if request("answer5") = "1D" then numcorr = numcorr + 1
if request("answer6") = "1C" then numcorr = numcorr + 1
if request("answer7") = "1D" then numcorr = numcorr + 1
if request("answer8") = "1D" then numcorr = numcorr + 1
if request("answer9") = "9C" then numcorr = numcorr + 1
if request("answer10") = "10B" then numcorr = numcorr + 1

Select case numcorr
case 0
response.redirect "2003TechnoHHQuizScore0"
case 1
response.redirect "2003TechnoHHQuizScore1"
case 2
response.redirect "2003TechnoHHQuizScore2"
case 3
response.redirect "2003TechnoHHQuizScore3"
case 4
response.redirect "2003TechnoHHQuizScore4"
case 5
response.redirect "2003TechnoHHQuizScore5"
case 6
response.redirect "2003TechnoHHQuizScore6"
case 7
response.redirect "2003TechnoHHQuizScore7"
case 8
response.redirect "2003TechnoHHQuizScore8"
case 9
response.redirect "2003TechnoHHQuizScore9"
case 10
response.redirect "2003TechnoHHQuizScore10"
end select
%>

<INPUT TYPE=SUBMIT VALUE="SUBMIT" style="font-weight:
bold">
&nbsp;
 
Hi,
your page would look something like this
<%
if request.form <> "" then
' your redirect code
else
%>
....put your form here
<%end if%>
in your select statement that does the redirect you need an extension for
the page, eg
response.redirect "page.asp"
for brevity you could also lose the select amd just do
<%
response.redirect "2003TechnoHHQuizScore" & numcorr & ".asp"
%>

Jon
Microsoft MVP - FP
 
I don't know where to begin, nor how to phrase this without sounding
insulting. I'll just have to hope you understand my intentions, and believe
me, my intention is to help you out. My first advice would be, if you're
going to program, learn to program first. Programming is an exact science,
and there is no room for guesswork. In particular, if you want to write a
server-side application with ASP or ASP.Net, you need to know exactly what
you're doing, as the Internet HTTP environment is particularly tricky to
write for.

ASP (Active Server Pages) is a technology for creating HTML documents
dynamically on the client browser. The VBScript code runs entirely on the
web server, and not on the client browser, unlike JavaScript, for example.
It never even makes it into the HTML delivered to the browser. In order to
be effective with ASP, it is important to understand a bit about HTTP and
HTML, and how they work, as your app is going to be intimately involved with
both. The following article (and several others like it) on my web site
should give you a good background:

http://www.takempis.com/aspfundamentals.asp

I realize that this may seem heavy-handed, but seriously, in my experience
as a programmer, I have found it to be true that the more time you spend up
front planning and understanding what you need to do, the less time you will
spend in the long run trying to make it happen. And I could do you a
disservice and simply tell you what to do, in which case, the next time you
had to do anything with this, or anything like it, you would be lost. But I
want you to be able to do this on your own next time, quickly and easily, so
I feel that you should understand my solution before I give it to you. That
said, let's get down to the specifics of your problem.

First, I have no idea what you mean by "embedding code in a form." The code
you posted was form HANDLER code, not code that would run IN a form. An HTML
form is a device for user input, and has an ACTION property that points to
the URL of the form handler, which would, in this case, be an ASP page. It
could be the same form page, depending upon what your requirements are, but
it doesn't really matter, as long as the form's ACTION property points to
it, and it handles the form.

The code you posted has nothing to do with a database, so there is no SELECT
statement involved. The code simply checks the values of a number of form
fields, and increments a value depending upon what those values are. The
Select Case statement you posted simply redirects to a different page
depending upon the value of your numcorr variable. Of course, the page names
you put into your Select Case statement are incorrect, as they have no file
extensions.

So, the code you posted will run as it stands, as long as it is properly
placed in the page, and you give the HTML documents you are redirecting to
real file names. As this is an ASP script, you need to start with
server-side scripting tags. Here is what should be on your form handler
page:

<%
Dim numcorr
numcorr = 0
if request("answer1") = "1C" then numcorr = numcorr + 1
if request("answer2") = "1E" then numcorr = numcorr + 1
if request("answer3") = "1C" then numcorr = numcorr + 1
if request("answer4") = "1E" then numcorr = numcorr + 1
if request("answer5") = "1D" then numcorr = numcorr + 1
if request("answer6") = "1C" then numcorr = numcorr + 1
if request("answer7") = "1D" then numcorr = numcorr + 1
if request("answer8") = "1D" then numcorr = numcorr + 1
if request("answer9") = "9C" then numcorr = numcorr + 1
if request("answer10") = "10B" then numcorr = numcorr + 1

Select case numcorr
case 0
response.redirect "2003TechnoHHQuizScore0.htm"
case 1
response.redirect "2003TechnoHHQuizScore1.htm"
case 2
response.redirect "2003TechnoHHQuizScore2.htm"
case 3
response.redirect "2003TechnoHHQuizScore3.htm"
case 4
response.redirect "2003TechnoHHQuizScore4.htm"
case 5
response.redirect "2003TechnoHHQuizScore5.htm"
case 6
response.redirect "2003TechnoHHQuizScore6.htm"
case 7
response.redirect "2003TechnoHHQuizScore7.htm"
case 8
response.redirect "2003TechnoHHQuizScore8.htm"
case 9
response.redirect "2003TechnoHHQuizScore9.htm"
case 10
response.redirect "2003TechnoHHQuizScore10.htm"
end select
%>

Note that, since this page redirects, and is therefore never seen on the
client, it is not necessary to include any HTML in the Page.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Thanks for all of your information.. i will have to work
on this later, at home.. being that I'm at work right
now.. programming.. not web programming but site
applications.. just one question.. are you saying I can't
use the select statement because there is no database
involved.. i don't believe this to be true.. I've used
them plenty of times without database involvement and they
seem to work fine. Like I said.. thanks for taking the
time to look at my post and give me feedback but when you
say learn to program first.. i'm abit confused.. I know
you don't know me but I do know I am a programmer and
(correct me if I'm wrong) but I believe the only thing
that you corrected was to include my file extensions.. on
my re-directing of pages.. Was there something else that I
missed. And when I said "embedding code in a form".. sorry
if you didn't understand this.. i figured the first part
of my statement "my first time" would clear anything i may
have had wrong. thanks again for your information.. i will
try and get it working later.
 
applications.. just one question.. are you saying I can't
use the select statement because there is no database
involved.. i don't believe this to be true.. I've used

A SELECT Statement is a database query. A Select Case statement is a VB
programming construct. I am guessing now that you meant "Select Case
Statement" rather than "SELECT Statement."

As for being a programmer, please pardon me for making a wrong assumption
there. Many people who have had some VB experience writing executables and
scripts find themselves totally at sea when working within the HTTP
enviroment, which, as I mentioned earlier, is much more difficult, due to
state considerations and other web-centric environmental conditions.
Understanding how HTTP and HTML works will be of great value to you if you
continue to work with ASP and/or ASP.Net.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top