This topic is locked

Checking for errors

6/5/2007 8:51:53 AM
ASPRunnerPro General questions
M
MikeGinMN author

Is it possible to check the info entered into an add and/or edit page to make sure things are correct? Example I have 5 boxes for events (3 individual and 2 team) a person can be in up to 4 (3 individual 1 team or 2 individual and 2 team) so I would like to make sure they don't try to add the fifth one. I'm sure I just have to check the avalue of each to see that it is empty - but am not sure how to display a message and/or keep it on the page.
Also would like to make sure quailifying score - depending on event is in correct form Example timing event would be HH:MM:SS.T
If you could point me in the right direction, I would appreciate it
Thanks for a super product <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=5429&image=1&table=forumtopics' class='bbc_emoticon' alt=':huh:' />

Sergey Kornilov admin 6/5/2007

Use BeforeEdit event to validate entered values.
See comments in events code that explain what you need to do to cancel editing and stay on the Edit page.

M
MikeGinMN author 6/5/2007

Thats what I thought - so I must be doing something wrong in before event I have this
Function BeforeEdit(dict, where)
' Parameters:

' dict - Scripting.Dictionary object.

' Each field on the Edit form represented as 'Field name'-'Field value' pair

' where - string with WHERE clause pointing to record to be edited

if avalues.exists("Event01")and avalues.exists("Event02") and avalues.exists("Event03") and avalues.exists("TmEvent01") and avalues.exists("TmEvent02") then
'** Display a message on the Web page ****

Response.Write "You need to select only a total for four events"
BeforeEdit = False
else
BeforeEdit = True

' set BeforeEdit to True if you like to proceed with editing this record

' set it to False in other case
end if

End Function
But it still adds the all of the evnts - so what am I doing wrong
Thanks

F
funklet 6/5/2007

Mike,
You will need it to be more like this:
[codebox]Function BeforeEdit(dict, where)

if (dict("Event01") <> "") and (dict("Event02") <> "") and (dict("Event03") <> "") and (dict("TMEvent01") <> "") and (dict("TMEvent02") <> "") then

message="You need to select only a total for four events"

BeforeEdit = False

else

BeforeEdit = True

end if

End Function[/codebox]

The reason for the dict is that the values have not yet been added to the table and only exist in the dict recordset object so that they can be used before committed to the database.
The time validation is a it more tricky..
You are going to need to use the same type of event but with code something like this.
[codebox]Function BeforeEdit(dict, where)

if isdate(dict("timevariable")) then

beforeedit = true

else

message= "This is not a valid time, please re-enter"

beforeedit = false

end if

End Function[/codebox]
You could go further and check for the prescence of a ':' at positions 3 and 6 of the string etc. etc. The more complicated you make this bit the more difficult it is for them to enter an incorrect value.

If a wrong value is an absolute no-no then you are going to have to check that the numeric portion of each number pair is within the correct range.
Examples

[codebox]

if (mid(dict("timevalue"),3,1) <>":") or (mid(dict("timevalue"),6,1)<>":") etc. etc
if (cint(left(dict("timevalue"),2)) <25) and cint(mid(dict("timevalue"),4,2)) <59 etc. etc.
message = "You must enter the time in the format ""HH:MM:SS.T"""

[/codebox]
I hope this is of help.
Regards

M
MikeGinMN author 6/5/2007

I copied the first part of your programming into the before add event - but it still adds the event. The terms Event01, Event02 and etc are the names of the fields within the table they go into - does that make a difference?

Sergey Kornilov admin 6/5/2007

What is the data type of Event01, Event02, ... fields?
You might need to check if field is NULL vs empty string.

Use IsNull() function for this purpose.

M
MikeGinMN author 6/6/2007

I appreciate all the help - but am not getting the results
The fields are all varchar in a SQL DB with a length of 10 characters. I use a drop down list to pick the event for each of the 3 possible individual and 2 possible team events
I put in the following in beforeadd/beforeupdate record
Function BeforeEdit(dict, where)
' Parameters:

' dict - Scripting.Dictionary object.

' Each field on the Add form represented as 'Field name'-'Field value' pair

if IsNull(dict("Event01")) or IsNull(dict("Event02")) or IsNull(dict("Event03")) or IsNull(dict("TmEvent01")) or IsNull(dict("TmEvent02")) then
'** Display a message on the Web page ****

BeforeEdit = True
' set BeforeAdd to True if you like to proceed with adding new record

' set it to False in other case

else

message="You need to select only a total for four events"

BeforeEdit = False

end if
End Function
Basically if any of those 5 fields are empty - I want to update/add record - if all five come back as not null then I need to display the message. I'm sure it is an error between the keyboard and my computer - but can't seem to see what the issue is
Thanks again for everyones help - I wish I was half a smart as you guys and gals are

Sergey Kornilov admin 6/6/2007

Mike,
you need to troubleshoot your code to see what goes wrong.
Add the following in the beginning of event:

Response.write "Event01: " & dict("Event01") & ":" & IsNull(dict("Event01")) & "<br>"


Repeat the same for all 5 fields.
This can help you see what are real field values and how you can deal with it.

M
MikeGinMN author 6/6/2007

I think I'm getting there - one other question regarding error checking - is it possible to have the message appear like a popup so that it doesn't interfer with the original pages layout?

Sergey Kornilov admin 6/7/2007

Try this:
Response.Write "<script>alert('I\'m a popup window')</script>"

M
MikeGinMN author 6/11/2007

Thank You for all the help - The only way I got it to come back with a correct response (it came back in "IsNull" as false even when nothing was in it and also gave a false if I used "") was to check the length of each field to see if it was equal to zero, if all five came back as greater than zero it work. I appreciate all the help - I greatly appreciate your product and the support you supply
Have a great day