NatH
Posts: 9
|
| Posted: 01/01/2005, 8:38 AM |
|
ASP, CCS 2.3.2.2.4., XP Professiona
Can someone tell me why the code below does not work. I am attempting to comapare the values in two fields and if true redirect to another page.
table Name = Classes
Fields
ClassID
ClassName
ClassMaxNumber (indicates the maxium number of students per class)
ClassCount (Incremented every time a students register for a class)
============== THIS CODE DOES NOT WORK =================
Loaded in "After Execute Insert" event. The session variable is initialized in another event when the student register.
Dim CurrentCount, MaxCount
CurrentCount = CCDLookUp("ClassCount","Classes","ClassID=" &session("class_id"), DBadminDB)
MaxCount = CCDLookUp("ClassMaxNumber","Classes","ClassID=" &session("class_id"), DBadminDB)
If CurrentCount = MaxCount then
Redirect = "Success.asp"
end if
============ Code that updates the above fields ========
This code works fine. It is executed after a student successfully registers for a class and before the above code is executed.
Dim SQL
Dim Connection
Dim ErrorMessage
Dim testnumber
SQL = "Update Classes set ClassCount = ClassCount + 1 WHERE ClassID = " & session("class_id")
Set Connection = New clsDBadminDB
Connection.Open
Connection.Execute(SQL)
ErrorMessage = CCProcessError(Connection)
Connection.Close
Set Connection = Nothing
On Error Goto 0
Loaded in "After Execute Insert" event
Thanks,
NatH
|
 |
 |
Don Safar
|
| Posted: 01/01/2005, 9:56 AM |
|
You would get a true condition only when the class is full (MaxCount).
Should your statement be as below:
If CurrentCount <= MaxCount then
Redirect = "Success.asp"
end if
To faciliate debugging you could check the values with the following two
lines before the if statement
response.write CurrentCount & " - " &MaxCount
response.end
|
|
|
 |
NatH
Posts: 9
|
| Posted: 01/01/2005, 11:38 AM |
|
Don,
Thanks for your quick reply.
Two responses.
1. You are correct when you state that I would get a true condition only when the class is full based on the code provided. This is exactly the condition that I wish to test, when the class is full, I want to redirect the user to another page.
2. Your debugging tip helped me to understand that I was testing the two fields before they were actually updated in the database. To further test my code, I purposely made the values in the two fields equal and ran it again. When I ran the code, it still failed to redirect to the noted page. (yes, I used the debug tip to validate that the two fields are equal).
I am not an experience coder (learning as I go), and any suggestion you may proivide would be appreciated.
As info, I have included the code used to add the student info to the "Student" table. It works and acccomplishes the following:
1. Determines the values of both the CurrentCount and ClassMaxNumber fields.
2. The test condition detemines if a class is full or not. If it is not full, the record insertAllowed value = True and the user is provided a message that their registration was successful.
I am providing the code in the event it is causing the problem or perhaps this is where I want to redirect the user after a successful registration. By the way the success.asp page contains the date, location and other information for the registered class. It is just a plain text page.
====== Student Registration Code ==================
Function Student_BeforeInsert() 'Student_BeforeInsert @2-EC824CA7
'Custom Code @11-73254650
' -------------------------
Dim CurrentCount, MaxCount, class_id
Session("class_name") = CCDLookUp("ClassName","Classes","ClassID="&student.ClassID.value, DBadminDB)
Session("class_id") = student.ClassID.value
CurrentCount = CCDLookUp("ClassCount","Classes","ClassID=" &student.ClassID.value, DBadminDB)
MaxCount = CCDLookUp("ClassMaxNumber","Classes","ClassID=" &student.ClassID.value, DBadminDB)
If CurrentCount < MaxCount Then
Student.Errors.addError("***** REGISTRATION SUCCESSFUL *****")
Student.InsertAllowed = True
Else
Student.InsertAllowed = False
Student.Errors.addError("***** SORRY, THE SELECTED CLASS IS FULL *****")
End if
' -------------------------
'End Custom Code
Thanks again,
NatH
NatH
|
 |
 |
NatH
Posts: 9
|
| Posted: 01/01/2005, 12:26 PM |
|
Don,
My comment relative to the use of the "success.asp" page is misleading. In the original post I was using it only to test the redirect and the test condition. Once I get it to work properly, I am going to substitute the "success.asp" page with the aspmail code to send an email to the class administration indicating that the class is full.
I hope I have not confused things too much.
Thanks again,
NatH
|
 |
 |
NatH
Posts: 9
|
| Posted: 01/02/2005, 7:38 AM |
|
All,
Pease ignore this posting. I have resolved my problems by taking a different approach.
I am using the On validate event to test whether a class is full or not and displaying the appropriate error message. If a registration is successful, the student is added to the database and redriected to a page with registration information.
Again, thanks Don for your initial response.
NatH
|
 |
 |
|