textbox to pic9

Hi,

i have textbox in Window Form.

Can i move textbox to cobol pic 9 field?

textbox have max "999" ou "  9"....

But my field in cobol is pic 9.

  • You could do something like the following which will make sure that the data entered is actually numeric before moving it to the pic 9 field:

          01 field1   pic 9(5).
          01 numfield binary-long.
          ...          
              if type Int32::TryParse(textbox1::Text, numfield)
                 move numfield to field1
              else
                 invoke type MessageBox::Show("Error not numeric")
              end-if

  • can lock editing a textbox to only accept numbers?

    -------

    what is necessary to learn how to use windows forms?

    what do you recommend to be studied to use Visual Cobol?

    Note: I already know cobol.

  • Hi Claudio

        This is what I use to make sure I only get valid characters:

          method-id tbxPrice_KeyPress final private.

          Working-Storage Section.

          01 StringData         type String.

          01 ValidData          type String  Value "0123456789 -.".

          procedure division using by value sender as object e as type System.Windows.Forms.KeyPressEventArgs.

         **** First capture a character *****

              Set StringData TO e::KeyChar.

         ***** Now check if that character is in your validation string.    

              If Not ValidData::Contains(StringData) And Not type Char::IsControl(e::KeyChar)

                  Set e::Handled to True

              End-If.

         ***** I also test for no more than 1 decimal point *****

         ***** since only decimal points (periods) can get this far, I test for "Punctuation" *****

         ***** "CNT" needs to be initialized when the textbox gets focus *****  

              If type Char::IsPunctuation(e::KeyChar) Add 1 to CNT.

              If type Char::IsPunctuation(e::KeyChar) And CNT > 1

                 Set e::Handled to True

              End-If.

          end method.

  • Hi Claudio

        This is what I use to make sure I only get valid characters:

          method-id tbxPrice_KeyPress final private.

          Working-Storage Section.

          01 StringData         type String.

          01 ValidData          type String  Value "0123456789 -.".

          procedure division using by value sender as object e as type System.Windows.Forms.KeyPressEventArgs.

         **** First capture a character *****

              Set StringData TO e::KeyChar.

         ***** Now check if that character is in your validation string.    

              If Not ValidData::Contains(StringData) And Not type Char::IsControl(e::KeyChar)

                  Set e::Handled to True

              End-If.

         ***** I also test for no more than 1 decimal point *****

         ***** since only decimal points (periods) can get this far, I test for "Punctuation" *****

         ***** "CNT" needs to be initialized when the textbox gets focus *****  

              If type Char::IsPunctuation(e::KeyChar) Add 1 to CNT.

              If type Char::IsPunctuation(e::KeyChar) And CNT > 1

                 Set e::Handled to True

              End-If.

          end method.

  • Thank you Jerry.

    These commands:

    Contains :: (StringData)

    Char :: IsControl

    Char :: IsPunctuation (e KeyChar ::)

    This is new to me.

    This command is visual studio? windows forms?

    where I learn more about this?

  • Hi Claudio,

    You could also look at using a maskedtextbox control which allows you to define an input mask against which all user input will be validated.

    The syntax that you question is Object-Oriented COBOL being used with the .NET Framework classes.
    The Contains is a method in the System.String class and the Char::IsControl, etc are from the System.Char type.

    When using managed COBOL to create managed code applications like Windows Forms, WPF, WCF, etc. you will make extensive use of these classes which are part of the .NET Framework.

    If you are new to OO-COBOL then I would recommend that you look through the Introduction to OO COBOL here:

    There are many books on the subject of programming with the .NET Framework, including the help documentation that is provided with Visual COBOL although most of the examples that you see will be from Microsoft and will be for C# or VB.NET and not COBOL.

    For COBOL specific examples you should start up the Samples Browser under All Programs-->Micro Focus Visual COBOL-->Samples and click on Managed on the left hand side and then look through the samples on the right hand side of the window.

    Thanks.

  • i create method

    "textbox_codigo_keypress" with sample code "tbxPrice_KeyPress".

    In "method-id InitializeComponent private."

    i try:

    invoke textbox_codigo::add_KeyPress(new System.EventHandler(self::textbox_codigo_KeyPress))

    But display this error:

    Error 1 COBCH0842 : Class member 'textbox_codigo_KeyPress' has multiple definitions with same signature

  • When you create an event handler in the Forms Designer properties window it automatically generates the code for this event handler in the .designer.cbl file as is shown in your first screen shot.

    This event handler is already wired up and the specified method will be callled each time the event occurs.

    This means that you cannot add a line like:

       invoke textbox_codigo::add_KeyPress(new System.EventHandler(self::textbox_codigo_KeyPress))

    to your initializeComponent method as, like the error states, this event handler already exists.

    What is it that you are trying to accomplish here?

  • This image is my form.

    In "CODIGO" only enter "0 to 9"

    because in FD is PIC 9(03).

    I try use the SCRIPT "method-id tbxPrice_KeyPress final private" by JERRY posted in this topic.

    Your script with "invoke type MessageBox::Show("Error not numeric")"

    is good, display "Error..." but do not clear char inserted.

  • This image is my form.

    In "CODIGO" only enter "0 to 9"

    because in FD is PIC 9(03).

    I try use the SCRIPT "method-id tbxPrice_KeyPress final private" by JERRY posted in this topic.

    Your script with "invoke type MessageBox::Show("Error not numeric")"

    is good, display "Error..." but do not clear char inserted.