[Gambas-user] Set all fields(contol.value) on a panel to a default value?

Ian Roper westozscribe at gmail.com
Sun May 7 01:45:07 CEST 2023


Greetings,

I've used this subroutine for about 3 years with little problem.

Note#

The one error I get is a rare /intermittent /issue with the clearing of 
a text control text.  (Noted by the commented arrow in the code)
I've looked at this error in great detail but have never been able to 
find a cause.

When it occurs, it presents the "not an enumeration" error.  I can close 
gambas and restart, and still get the error.
I can restart my system and still get the error.
The next day, no changes and run the same function and get no errors. It 
is very rare. I may go many months without it occurring.
I have not had the error since the last update and I'm hopeful that it's 
now gone for good. If it happens to you, then you at least have some 
history.

------------------------------------------------------------------------------------------------------------------

Public Sub FormResetControls(InControl As Container)

   Dim ControlElement As Control
   Dim TmpInt As Integer
   Dim TPanel As TabPanel
   Dim TStrip As TabStrip
   Dim EmptyString As Variant = ""

   For Each ControlElement In InControl.Children

     If ControlElement Is Frame Then FormResetControls(ControlElement) 
'It may have children so do a recursive search
     If ControlElement Is Panel Then FormResetControls(ControlElement) 
'It may have children so do a recursive search

     If ControlElement Is TabPanel Then
       TPanel = ControlElement
       For TmpInt = 0 To TPanel.Count - 1
         FormResetControls(Tpanel[TmpInt]) 'It may have children so do a 
recursive search
       Next
     Endif

     If ControlElement Is TabStrip Then
       TStrip = ControlElement
       For TmpInt = 0 To TStrip.Count - 1
         FormResetControls(TStrip[TmpInt]) 'It may have children so do a 
recursive search
       Next
     Endif
     If ControlElement Is TextBox Then 
Object.SetProperty(ControlElement, "Text", EmptyString) ' <-----<<<<<
     If ControlElement Is TextBox Then 
Object.SetProperty(ControlElement, "Background", Color.White)
     If ControlElement Is TextArea Then 
Object.SetProperty(ControlElement, "Text", EmptyString)
     If ControlElement Is TextEditor Then 
Object.SetProperty(ControlElement, "Text", EmptyString)
     If ControlElement Is ValueBox Then 
Object.SetProperty(ControlElement, "Value", Null)
     If ControlElement Is CheckBox Then 
Object.SetProperty(ControlElement, "Value", 0)


     If ControlElement Is ComboBox Then
       If Object.GetProperty(ControlElement, "Count") > 0 Then 
Object.SetProperty(ControlElement, "Index", 0)
     Endif

     If ControlElement Is SpinBox Then
       TmpInt = Object.GetProperty(ControlElement, "MinValue")
       Object.SetProperty(ControlElement, "value", TmpInt)
     Endif

     If ControlElement Is DirBox Then Object.SetProperty(ControlElement, 
"value", "")

   Next

Catch
   Message( Error.Text )

End
----------------------------------------------------------------------------------------


Cheers,

Ian.




On 7/5/23 12:57 am, Dag JNJ wrote:
> Hi all,
> I am on a project with some SQL tables, similar GUIs with some fields 
> on a normal panel. I make one function to clear all the fields the 
> user can see. But I think I remember I saw a loop with /for each/ 
> we´here the controls have been manipulated, e.g. change value.
>
> I tried something like this
>
> /Public Sub Sta_Adr_clearfields_bt_Click()//
> //
> //    Dim xtb As TextBox//
> //
> //    For Each xtb In Sta_Adr_data_pnl//
> //        xtb.Text = ""//
> //    Next//
> //End//
> /
> I get /Sta_Adr_data_pnl/ is not an enumeration (I had to translate 
> from German by myself, hope that's the word).
> Either the syntax is wrong or I remember wrong.
>
> Any help? Thanks in advance
> Dag
>
> ----[http://gambaswiki.org/wiki/doc/netiquette  ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230507/015dd722/attachment.htm>


More information about the User mailing list