In this chapter a sample EditForm script is adapted and converted.
Assume the following COM-based script has been written in Isah version 4.0.3. It contains an edit form, a radio buttons group, a checkbox, a combobox, and an OnChange event:
Dim frm, rbg1, ch1, cb1
Sub Main
Set frm = Application.IsahForms.CreateEditForm
Set rbg1 = frm.AddRadioButtons("rbg1",,,,,"choice","one;two;three", 0, 1)
Set ch1 = frm.AddCheckBox("ch1",,,, "ch1 caption", False)
Set cb1 = frm.AddComboBox("cb1",,,,"cb1 lab","one;two;three", 0)
frm.ShowModal
End Sub
Sub IsahEvent_OnChange(Id)
If Id = rbg1.GetId Then
ch1.SetValue True
End If
If Id = ch1.GetId Then
If ch1.GetValue Then
cb1.ItemIndex = 2
End If
End If
End Sub
In Isah 4.0.3 the code above has the following behavior:
In Isah 4.0.5 the code has the following behavior:
As you can see, there is a difference in behavior when showing the form.
This can be addressed in the following ways:
The first solution allows you to change the script without requiring in-depth functional knowledge:
The first difference between Isah version 4.0.5 and Isah version 4.0.3 is that in version 4.0.5 the OnChange event of the radio buttons group is no longer called by the AddRadioButtons call. This problem can be solved by manually calling the OnChange event before the ShowModal call of the form.
A second difference between Isah version 4.0.3 and Isah version 4.0.5 is that if you are in an OnChange event sub and you change a component that also calls the OnChange sub (in this case by setting the value of the checkbox ch1), in version 4.0.5 this results in multiple, subsequent OnChange calls, whereas in version 4.0.3 the OnChange call(s) is (are) blocked. This can be simulated by adding a variable that blocks the OnChange event.
The first solution results in the following script code, which in version 4.0.5 forces the same behavior as in version 4.0.3:
Dim frm, rbg1, ch1, cb1, Nesting
Sub Main
Nesting = False
Set frm = Application.IsahForms.CreateEditForm
Set rbg1 = frm.AddRadioButtons("rbg1",,,,,"choice","one;two;three", 0, 1)
Set ch1 = frm.AddCheckBox("ch1",,,, "ch1 caption", False)
Set cb1 = frm.AddComboBox("cb1",,,,"cb1 lab","one;two;three", 0)
IsahEvent_OnChange(rbg1.GetId)
frm.ShowModal
End Sub
Sub IsahEvent_OnChange(Id)
If Nesting Then Exit Sub
Nesting = True
If Id = rbg1.GetId Then
ch1.SetValue True
End If
If Id = ch1.GetId Then
If ch1.GetValue Then
cb1.ItemIndex = 2
End If
End If
Nesting = False
End Sub
The second solution requires in-depth functional knowledge of the script, and will change the calls in such a way that the behavior will be the same as in version 4.0.3.
It should be noted that in version 4.0.5 the Add... functions of the form no longer trigger the OnChange event. In this script, this behavior can be utilized by setting the checkbox in the original script to a default value of True instead of False. In this simple script, this change will be enough to bring the behavior of version 4.0.5 in line with that of version 4.0.3.
In practice, the second solution will be a lot more difficult to realize than in the example given here. In most cases, you will first have to identify which components in version 4.0.3 generate events on opening the form, and determine how often the events are activated. Once you have done so, you should change the script code in version 4.0.5 by: