Create one Script for each Form field event.
As you design your form and add code to field events it becomes harder to keep track of all that code. My solution it to create a universal script for each field event.....ie..scripts for ONARRIVE, ONDEPART etc....
In my example below I show a script for the ONARRIVE event. Use comments liberally so you can Identity which code fragements apply to which field ONARRIVE event. This example script for on ONARRIVE events changes a conditional object which displays hotkeys available for that field, depending on the mode of the form.
script->ON_ARR
''This variable will be used to hold the field object name. It doesn't have to be global but I am a belt and suspenders type of guy. If I want to make use of this variable value later on in another session I don't have to go back and rewrite the code.
dim global fname as C
''Sets a pointer to the form in use
f = parentform.this
''This retrieves the field object name. Knowing the field object name allows you to assign code to different fields, using a goto statement which jumps to the appropiated code fragment for a field or execute code fragements nested in IF or SELECT statements.
fname = this.name()
''Check the form mode, if in view mode, no change to the conditional object.
if F.restrict_enter=.T. .or. F.restrict_change=.T. then
goto skip_1
end if
''This is the start of the if statements which execute code depending on the object name. You retrieve the object name using explorer in the code editor. IMPORTANT !! the form must be loaded to see the objects. In the explorer window, expand objects/windows/"your form". A long list of objects appears. Object names are preceded by a box with an "i" inside. Drag the name you want to the editing screen. Remove the form name pointer leaving you with just the object name.
if fname = "Advisor0" .or. fname = "City" .or. fname = "Province" then
dis = "choices"
f = parentform.this
f:Cond10.refresh()
goto skip_1
end if
if fname = "Cntct_Date" .or. fname = "Deliv_Date" .or. fname = "Folup_Date" then
dis = "date"
f = parentform.this
f:Cond10.refresh()
goto skip_1
end if
''This is here for possible future use
skip_2:
''this is the default if the previous conditions do not apply.
dis = "Save"
f = parentform.this
f:Cond10.refresh()
skip_1:
end
--------------------
The great benefit to this approach is no more jumping to different fields to edit or create new code in field events. You just go to one place, the script for that event.
As you design your form and add code to field events it becomes harder to keep track of all that code. My solution it to create a universal script for each field event.....ie..scripts for ONARRIVE, ONDEPART etc....
In my example below I show a script for the ONARRIVE event. Use comments liberally so you can Identity which code fragements apply to which field ONARRIVE event. This example script for on ONARRIVE events changes a conditional object which displays hotkeys available for that field, depending on the mode of the form.
script->ON_ARR
''This variable will be used to hold the field object name. It doesn't have to be global but I am a belt and suspenders type of guy. If I want to make use of this variable value later on in another session I don't have to go back and rewrite the code.
dim global fname as C
''Sets a pointer to the form in use
f = parentform.this
''This retrieves the field object name. Knowing the field object name allows you to assign code to different fields, using a goto statement which jumps to the appropiated code fragment for a field or execute code fragements nested in IF or SELECT statements.
fname = this.name()
''Check the form mode, if in view mode, no change to the conditional object.
if F.restrict_enter=.T. .or. F.restrict_change=.T. then
goto skip_1
end if
''This is the start of the if statements which execute code depending on the object name. You retrieve the object name using explorer in the code editor. IMPORTANT !! the form must be loaded to see the objects. In the explorer window, expand objects/windows/"your form". A long list of objects appears. Object names are preceded by a box with an "i" inside. Drag the name you want to the editing screen. Remove the form name pointer leaving you with just the object name.
if fname = "Advisor0" .or. fname = "City" .or. fname = "Province" then
dis = "choices"
f = parentform.this
f:Cond10.refresh()
goto skip_1
end if
if fname = "Cntct_Date" .or. fname = "Deliv_Date" .or. fname = "Folup_Date" then
dis = "date"
f = parentform.this
f:Cond10.refresh()
goto skip_1
end if
''This is here for possible future use
skip_2:
''this is the default if the previous conditions do not apply.
dis = "Save"
f = parentform.this
f:Cond10.refresh()
skip_1:
end
--------------------
The great benefit to this approach is no more jumping to different fields to edit or create new code in field events. You just go to one place, the script for that event.