Page 1 of 1

reseting the text in a textbox

Posted: Saturday 19th December 2020 5:22am
by grayghost4
Is there a way to reset the text of a text box to the text assigned in the properties
For Each oObj In dataaray.Children
         oObj.text = ""   '  I would like this to reset to the text in the properties text 
    Next

Re: reseting the text in a textbox

Posted: Saturday 19th December 2020 6:06am
by stevedee
My only suggestion is that you use the .Tag property.

At the start of your program copy initial text to Tag, something like:-
For Each oObj In dataaray.Children
         oObj.Tag = oObj.Text  '  store initial properties text 
    Next
Then you can get it back:-
For Each oObj In dataaray.Children
         oObj.Text = oObj.Tag  '  restore the text in the properties text 
    Next

Re: reseting the text in a textbox

Posted: Saturday 19th December 2020 6:28am
by grayghost4
Thanks that worked !

I have a lot to learn ;)

Re: reseting the text in a textbox

Posted: Saturday 19th December 2020 6:56am
by stevedee
The Tag property is often under-used (or over-looked) but its great for poking things away that you might need later.
It often saves you creating a Public variable, and as its a Variant, its very flexible.

Re: reseting the text in a textbox

Posted: Saturday 19th December 2020 5:16pm
by grayghost4
It looks like this will also do the same thing. I needed to use "Try" because dataaray has both text and value boxes.
This will leave Tag for other uses ;)
        For Each oObj In dataaray.Children
         Try oObj.Placeholder = oObj.Text
    Next
 For Each oObj In dataaray.Children
        Try oObj.Clear
    Next
TextBox.Placeholder (gb.qt4)

Property Placeholder As String

Return or set the placeholder text, i.e. the text displayed when the Text property is void.

Re: reseting the text in a textbox

Posted: Sunday 20th December 2020 11:30pm
by Quincunxian
This is a routine that I use to prepare the controls on a form for validation.
The passed container is normally a panel or frame which contains all the 'maintenance' controls.
{text boxes, text areas, combo boxes, checkboxes etc...}
It will then recursivity search for controls and then set their chosen parameters to whatever it is that I need using the
Object.SetProperty & Object.getProperty commands.
This allows you to overcome the limited set of parameters exposed when you examine the child controls.

The main one is to Trim the text input areas as this overcomes a common problem with user input.
The InColour is used to return the display colour of a control back to a standard. In most cases this is black.
As part of a validation routine, I turn the label for the control red if an error is detected to assist the user in
quickly identifying where the error is.
Public Sub FormPrepareForValidation(InControl As Object, InColor As Integer)

  Dim ControlElement As Control

  For Each ControlElement In InControl.Children
    If ControlElement Is Frame Then FormPrepareForValidation(ControlElement, InColor) ' It may have children so do a recursive search"
    If ControlElement Is Panel Then FormPrepareForValidation(ControlElement, InColor) ' It may have children so do a recursive search"
    If ControlElement Is Label Then Object.SetProperty(ControlElement, "ForeGround", InColor)
    If ControlElement Is TextBox Then Object.SetProperty(ControlElement, "Text", Trim(Object.getProperty(ControlElement, "Text")))
    If ControlElement Is TextArea Then Object.SetProperty(ControlElement, "Text", Trim(Object.getProperty(ControlElement, "Text")))
    If ControlElement Is RadioButton Then Object.SetProperty(ControlElement, "ForeGround", InColor)
    If ControlElement Is CheckBox Then Object.SetProperty(ControlElement, "ForeGround", InColor)
    If ControlElement Is TabPanel Then Object.SetProperty(ControlElement, "ForeGround", InColor)
    If ControlElement Is TabStrip Then Object.SetProperty(ControlElement, "ForeGround", InColor)
  Next

End
This subroutine uses the same concepts to Reset a container's controls, ready to accept new input.
Public Sub FormResetControls(InControl As Container)

  Dim ControlElement As Control
  Dim ChildControl As Control
  Dim TmpInt As Integer
  Dim TPanel As TabPanel
  Dim TStrip As TabStrip

 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 TPanel.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", "")
    If ControlElement Is TextBox Then Object.SetProperty(ControlElement, "Background", Color.White)
    If ControlElement Is TextArea Then Object.SetProperty(ControlElement, "Text", "")
    If ControlElement Is TextEditor Then Object.SetProperty(ControlElement, "Text", "")
    If ControlElement Is ComboBox Then Object.SetProperty(ControlElement, "Index", 0)
    If ControlElement Is ValueBox Then Object.SetProperty(ControlElement, "value", Null)
    If ControlElement Is CheckBox Then Object.SetProperty(ControlElement, "value", 0)
    If ControlElement Is SpinBox Then Object.SetProperty(ControlElement, "Value", Object.GetProperty(ControlElement, "MinValue"))
    
  Next

Re: reseting the text in a textbox

Posted: Sunday 14th February 2021 2:17am
by Technopeasant
stevedee wrote: Saturday 19th December 2020 6:56am The Tag property is often under-used (or over-looked) but its great for poking things away that you might need later.
It often saves you creating a Public variable, and as its a Variant, its very flexible.
I had a bad habit of using it to store information that should be have been delineated as part of its own class file though. Like for game logic values. :lol: