How to convert C# function to Visual Cobol for .NET

private void limparTextBoxes(Control.ControlCollection controles)

{

    foreach (Control ctrl in controles)
    {     
        if (ctrl is TextBox)
        {
            ((TextBox)(ctrl)).Text = String.Empty;
        }
    }
}

To call

limparTextBoxes(this.Controls);

  • You don't say what version of Visual COBOL for .NET you're using. With recent dialects, it would be something like the following:


    method-id. limparTextBoxes.
    procedure division using by value controles as type Control.ControlCollection.
        declare ctrl as type Control
        perform varying ctrl through controles
            if ctrl instance of type TextBox
                declare tb as type TextBox = ctrl as type TextBox
                set tb::Text to string::Empty
            end-if
        end-perform
    end method limparTextBoxes.

    I haven't tried that. I didn't use all the most recent syntax enhancements, since I don't know which ones your version of Visual COBOL supports.

  • Verified Answer

    Thank you for your help. Your example works to forms without containers and in this post I forgot to specify this. I got as follows, do not know if it's the best way, but it works.

    method-id tsBtnLimpa_Click final private.

    procedure division using by value sender as object e as type System.EventArgs.

       invoke limpaCampos()

    end method.

    method-id. limpaCampos public.

        *> le os controles dentro do (container) panel principal        

        perform varying myobj as type Control thru self::panel::Controls

             *> limpa os textboxs dentro do panel principal

             if myobj instance of type TextBox

                declare tb as type TextBox = myobj as type TextBox

                set tb::Text to string::Empty

             end-if  

             *> limpa o checkBox dentro do panel principal

             if myobj instance of type CheckBox

                declare tb as type CheckBox = myobj as type CheckBox

                set tb::Checked to false

             end-if            

             *> limpa o maskedTextBox dentro do panel principal

             if myobj instance of type MaskedTextBox

                declare tb as type MaskedTextBox = myobj as type MaskedTextBox

                set tb::Text to string::Empty

             end-if          

             if myobj instance of type GroupBox

                *> limpa os controles dentro dos containers GroupBoxs

                perform varying ctrl as type Control thru myobj as type GroupBox::Controls

                       *> limpa textboxs

                       if ctrl instance of type TextBox

                          declare tb as type TextBox = ctrl as type TextBox

                          set tb::Text to string::Empty

                       end-if

                       *> limpa maskedTextBoxs

                       if ctrl instance of type MaskedTextBox

                          declare tb as type MaskedTextBox = ctrl as type MaskedTextBox

                          set tb::Text to string::Empty

                       end-if  

                end-perform

             end-if  

        end-perform

    end method.