Skip to main content

[Migrated content. Thread originally posted on 05 January 2012]

Hello,

What is the equivalen in Visual COBOL to this fragment of code in C#?
        [Category("Data")]
        [Description("Alert Message")]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

Thanks!

[Migrated content. Thread originally posted on 05 January 2012]

Hello,

What is the equivalen in Visual COBOL to this fragment of code in C#?
        [Category("Data")]
        [Description("Alert Message")]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

Thanks!
You can do this in a couple of ways.
You will have to add the following namespace import directive to the top of the program or in the project Properties:

$set ilusing"System.ComponentModel"

Since it is defining a simple property that only sets or gets the value of a field you could do this as follows:


01 wsmessage string property as "Message"
       attribute Category("Data")
       attribute Description("Alert Message").


This automatically generates the get and set methods for you.

Or if you needed to change the get or set methods of the property to do something more advanced then you could specify as follows:


01 wsmessage string.
...
method-id set property wsMessage as "Message"
     attribute Category("Data")
     attribute Description("Alert Message").
procedure division using by value the-value as string.
     set wsmessage to the-value
end method.
       
method-id get property wsMessage as "Message"
     attribute Category("Data")
     attribute Description("Alert Message").
procedure division returning the-value as string.
     set the-value to wsmessage
end method.


This is covered in the two example programs under C:\\Users\\Public\\Documents\\Micro Focus\\Visual COBOL 2010\\Samples\\COBOL for .NET\\ called:
CustomAttributes
Properties

You can also find these by opening the Visual COBOL Samples Browser from Start Menu-->All Programs-->Micro Focus Visual COBOL 2010-->Visual COBOL Samples under the COBOL for .NET category.

[Migrated content. Thread originally posted on 05 January 2012]

Hello,

What is the equivalen in Visual COBOL to this fragment of code in C#?
        [Category("Data")]
        [Description("Alert Message")]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

Thanks!
I have found another issue. After setting the base class and the interface for the new custom user control, I cannot see anymore the design pane. The page says "Unable to show the design pane due to any of these classes cannot be designed" (it is a translation from spanish). If I do the same in C#, the page is shown with no problems.

This is the final code for my user control (it is only a simple test, as you can imagine):

      $set ilusing"System.ComponentModel"
       class-id TestUserControl.cntlCOBOLText is partial
                 inherits type UserControl
                 implements type IDisposable.
                 *>inherits type System.Windows.Forms.Form.
       
       working-storage section.
       01 wsmessage        string value "Initial text".
       
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           set txtMessage::Text to wsmessage.
           goback.
       end method.

     
       method-id set property wsMessage as "Message"
           attribute Category("Data")
           attribute Description("Alert Message").
       procedure division using by value the-value as string.
           set wsmessage to the-value.
           set txtMessage::Text to wsmessage.
       end method.

       method-id get property wsMessage as "Message"
           attribute Category("Data")
           attribute Description("Alert Message").
       procedure division returning the-value as string.
           set the-value to wsmessage
       end method.
                   
       end class.

       class-id TestUserControl.cntlCOBOLText is partial.
       
       01 label1 type System.Windows.Forms.Label.
       01 txtMessage type System.Windows.Forms.TextBox.
       01 components type System.ComponentModel.IContainer.
     
      *> Required method for Designer support - do not modify
      *> the contents of this method with the code editor.
       method-id InitializeComponent private.
       procedure division.
       set label1 to new System.Windows.Forms.Label
       set txtMessage to new System.Windows.Forms.TextBox
       invoke self::SuspendLayout
      *>
      *> label1
      *>
       set label1::AutoSize to True
       set label1::Location to new System.Drawing.Point( 12 9)
       set label1::Name to "label1"
       set label1::Size to new System.Drawing.Size( 19 13)
       set label1::TabIndex to 0
       set label1::Text to "Pi:"
      *>
      *> txtPi
      *>
       set txtMessage::Location to new System.Drawing.Point( 50 9)
       set txtMessage::Name to "txtPi"
       set txtMessage::ReadOnly to True
       set txtMessage::Size to new System.Drawing.Size( 73 20)
       set txtMessage::TabIndex to 1
      *>
      *> Form1
      *>
       set self::ClientSize to new System.Drawing.Size( 137 52)
       invoke self::Controls::Add(txtMessage)
       invoke self::Controls::Add(label1)
       *>set self::FormBorderStyle to type System.Windows.Forms.FormBorderStyle::None
       set self::Name to "Form1"
       set self::Text to "Form1"
       invoke self::ResumeLayout(False)
       invoke self::PerformLayout
       end method.

      *> Clean up any resources being used.     
       method-id Dispose override protected.
       procedure division using by value disposing as condition-value.
           if disposing then
             if components not = null then
               invoke components::Dispose()
             end-if
           end-if
           invoke super::Dispose(by value disposing)
           goback.           
       end method.

       end class.

[Migrated content. Thread originally posted on 05 January 2012]

Hello,

What is the equivalen in Visual COBOL to this fragment of code in C#?
        [Category("Data")]
        [Description("Alert Message")]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

Thanks!
It looks to me like you lost the following clause on the class-id for the designer class:

inherits type System.Windows.Forms.UserControl.


I created a test user control which looks like yours and when I remove this clause and rebuild the solution and try to display the control in design view I get the same error that you are seeing.

Try adding this clause back and see if it solves the problem for you.


[Migrated content. Thread originally posted on 05 January 2012]

Hello,

What is the equivalen in Visual COBOL to this fragment of code in C#?
        [Category("Data")]
        [Description("Alert Message")]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

Thanks!
Yes, it works like a charm.

It is strange that C# does not complain about that...

Thank you

[Migrated content. Thread originally posted on 05 January 2012]

Hello,

What is the equivalen in Visual COBOL to this fragment of code in C#?
        [Category("Data")]
        [Description("Alert Message")]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

Thanks!
Yes, it works like a charm.

It is strange that C# does not complain about that...

Thank you