Community in read only mode June 18 & 19
This community will be set in READ ONLY mode for a while on Tuesday June 18 into Wednesday June 19 while we import content and users from our Micro Focus Forums community site. MORE INFORMATION
Altair Absent Member.
Absent Member.
1473 views

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

Jump to solution

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);

0 Likes
1 Solution

Accepted Solutions
Highlighted
Altair Absent Member.
Absent Member.

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

Jump to solution

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.

2 Replies
Micro Focus Expert
Micro Focus Expert

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

Jump to solution

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.

Highlighted
Altair Absent Member.
Absent Member.

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

Jump to solution

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.

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.