This topic is locked

event coding before add

11/8/2006 8:34:27 PM
ASPRunnerPro General questions
hanb author

I am starting to code some event coding, but I am a lousy programmer since the cobol years.

I need to check the updates of a record, so that the sum of the fields in the record not exceeds total

the record is dec22, dec23, dec24, dec26, dec27, dec28, dec29, dec30 and TotaalPunten. These are days of a tournament and a total count.

One can get tickets for a certain day, where dec22 till dec28 is 1 point, dec 29 is 2 points, dec30 (Finals) is 3 points.

Anyone is given 10 points max.

The edit program can fill in the fields, and I want to calculate and check the total in the before add event.

Tried this code, but it always fails with error 500
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
'** Custom code ****
$max_kaarten = 10; // maximaal aantal te bestellen kaarten
session("TotaalPunten") = session("dec26") + session("dec27") +session("dec28")

session("TotaalPunten") = session("TotaalPunten") + session(dec29") 2

session("TotaalPunten") = session("TotaalPunten") + session("dec30")
3
'

' put your custom code here

If Session("TotaalPunten") < $max_kaarten

BeforeEdit = True

else

BeforeEdit = False

print "Maximum of 10 is reached"

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

' set it to False in other case
End Function
Is there someone who can help with this code?

Alexey admin 11/9/2006

Han,
try using this code:

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
'** Custom code ****
max_kaarten = 10 // maximaal aantal te bestellen kaarten
dict("TotaalPunten") = dict("dec26") + dict("dec27") +dict("dec28")

dict("TotaalPunten") = dict("TotaalPunten") + dict(dec29") 2

dict("TotaalPunten") = dict("TotaalPunten") + dict("dec30")
3
'

' put your custom code here

If dict("TotaalPunten") < max_kaarten then

BeforeEdit = True

else

BeforeEdit = False

message "<div class=message><<< Maximum of 10 is reached >>></div>"

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

' set it to False in other case
End Function

hanb author 11/9/2006

Alexey,
I have changed the code yo get all my fileds included and now I get the edit page on my screen, however I still do not see anything happening in the total, or in checking the data, no error messages.

I suppose the before edit kicks in when i hit the save button, so it should change at least the TotaalPunten field. But that still is zero.
Han
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
'** Custom code ****
max_kaarten = 10 // maximaal aantal te bestellen kaarten

free_kaarten = 4
dict("TotaalPunten") = dict("dec23") + dict("dec24") + dict("dec26") + dict("dec27") +dict("dec28")

dict("TotaalPunten") = dict("TotaalPunten") + dict("dec29") 2

dict("TotaalPunten") = dict("TotaalPunten") + dict("dec30")
3
'

' put your custom code here

If dict("TotaalPunten") <= max_kaarten then

BeforeEdit = True

else

BeforeEdit = False

message "<div class=message><<< Maximum of 10 is reached >>></div>"

end if

If dict("dec22") > free_kaarten then

BeforeEdit = False

message "<div class=message><< Maximum van 4 kaarten voor 22 december bereikt>>></div>"

else

BeforeEdit = True

end if

If dict("dec26") > free_kaarten then

BeforeEdit = False

message "<div class=message><< Maximum van 4 kaarten voor 26 december bereikt>>></div>"

else

BeforeEdit = True

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

' set it to False in other case
End Function

hanb author 11/9/2006

Small correction, I do see the totaal_punten field updated after placing the underscore, my mistake.

However I do not see any error message displayed, where does that go?

Alexey,

I have changed the code yo get all my fileds included and now I get the edit page on my screen, however I still do not see anything happening in the total, or in checking the data, no error messages.

I suppose the before edit kicks in when i hit the save button, so it should change at least the TotaalPunten field. But that still is zero.
Han
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
'** Custom code ****
max_kaarten = 10 // maximaal aantal te bestellen kaarten

free_kaarten = 4
dict("TotaalPunten") = dict("dec23") + dict("dec24") + dict("dec26") + dict("dec27") +dict("dec28")

dict("TotaalPunten") = dict("TotaalPunten") + dict("dec29") 2

dict("TotaalPunten") = dict("TotaalPunten") + dict("dec30")
3
'

' put your custom code here

If dict("TotaalPunten") <= max_kaarten then

BeforeEdit = True

else

BeforeEdit = False

message "<div class=message><<< Maximum of 10 is reached >>></div>"

end if

If dict("dec22") > free_kaarten then

BeforeEdit = False

message "<div class=message><< Maximum van 4 kaarten voor 22 december bereikt>>></div>"

else

BeforeEdit = True

end if

If dict("dec26") > free_kaarten then

BeforeEdit = False

message "<div class=message><< Maximum van 4 kaarten voor 26 december bereikt>>></div>"

else

BeforeEdit = True

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

' set it to False in other case
End Function

Alexey admin 11/9/2006

Han,
I'm sorry. Use

message = "<div ..."



instead of

message "<div ..."