Imagine the following situation: You open a (main) window FMain and from it you open another window F2. Then you edit selected data in window F2. Then you close the F2 window.
What answer would you have to the question: How do you realise the (necessary) data exchange between the window F2 and the (main) window FMain?
Normally, after closing F2, all data related to the form F2, such as text in a TextBox or the values of variables in the class F2, are lost. You can prevent this by setting the property F2.Persistent to 'True' for form F2. This is simple and effective, because you can access the data of the objects in the F2 window at any time - even if the F2 window has been closed.
The following experience of working with the Form.Persistent property can be given:
In the (main) window FMain you can change the property F2.Persistent via a CheckBox. It also displays the current values for the range of random numbers from the two control elements (TextBox First, TextBox Last) on F2. To realise this, the Public property has been set to the value 'True' for both SpinBars on F2.
Figure 188.8.131.52.1: (Main) window
In the presented project, the class F2 generates only random numbers, whose range in the window F2 can be changed via two control elements (SpinBar). The F2 window is not displayed when the (main) window is opened.
Figure 184.108.40.206.2: (Main) window with dialogue window F2 open.
If you now change the values for the range of random numbers, the changed values will be displayed in the (main) window at the next timer cycle. After closing F2, the result will not surprise you - the changes have not been applied:
Figure 220.127.116.11.3: (Main) window again with the default values values!
All updated data in F2 is deleted and reset to the default values because the Persistent property of F2 was set to the value 'False' when the (main) window was started. This is changed, as you can see from the highlighted CheckBox:
Figure 18.104.22.168.4: (Main) window with default values
New values for the range of random numbers are now set in the dialogue:
Figure 22.214.171.124.5: (Main) window and dialogue window F2
Figure 126.96.36.199.6: (Main) window
With the adopted, new dialogue values, F2 now only generates random numbers from 7 to 14 and displays them in the (main) window. Attention: Changing the state of the CheckBox does not automatically change the functionality of F2! You can only achieve this by calling F2 again after the value for the CheckBox has been set to 'not selected' and by closing F2:
Figure 188.8.131.52.7: (Main) window
The source code is given for both classes and commented:
 ' Gambas class file   Public Sub Form_Open()  FMain.Resizable = 'False'  ' FMain.Utility = 'True' ' ERROR!  Timer1.Delay = 1000  Timer1.Enabled = 'True'  Timer1.Trigger()  F2.Persistent = 'False'  End   Public Sub btnShowFormP_Click()  If ckBoxPersistence.Value Then  F2.Persistent = 'True'  Else  F2.Persistent = 'False'  Endif  F2.Showmodal()  End   Public Sub Timer1_Timer()  txbFirst.Text = F2.sbarFirst.Value  txbLast.Text = F2.sbarLast.Value  txlRandomNumber.Text = F2.SetRandomNumber()  End
Line 9 ensures that the persistence property of F2 is set to 'False' when the (main) window is opened.The timer (lines 6 to 8) generates the clock in which the random numbers (line 24) are retrieved and displayed as the function value of the SetRandomNumber() function from the Dialog class, and in lines 22 and 23 the default values for the current range of random numbers.
In lines 12 to 19, the persistence property of F2 is set and then the dialogue window F2 modal is displayed.
Source code F2.class:
 ' Gambas class file   Public Sub Form_Open()  F2.Center()  End   Public Function SetRandomNumber() As Integer  Randomize  Return Rand(sbarFirst.Value, sbarLast.Value)  End   Public Sub btnClose_Click()  F2.Close()  End
In line 9, the SetRandomNumber() function generates random numbers in the specified range. The Rand(First, Last) function generates numbers of type integer!The random number generator is initialised by Randomize with the current timestamp if the optional parameter is missing.