Skip to main content

What is the command to detect if the key that was pressed was numeric (e.g. 0 – 9) on a Windows Form? Or conversely, if the key that was pressed was NOT numeric? In C# the command is something like:

if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)

What is the command to detect if the key that was pressed was numeric (e.g. 0 – 9) on a Windows Form? Or conversely, if the key that was pressed was NOT numeric? In C# the command is something like:

if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)

The corresponding code in Visual COBOL would be:

if not type Char::IsControl(e::KeyChar) and not type Char::IsDigit(e::KeyChar) set textBox1::Text to "not digit" else set textBox1::Text to "is digit" end-if

The corresponding code in Visual COBOL would be:

if not type Char::IsControl(e::KeyChar) and not type Char::IsDigit(e::KeyChar) set textBox1::Text to "not digit" else set textBox1::Text to "is digit" end-if

The command you suggested was giving me an “Invalid conditional expression” error. So I tried it as follows: I moved the key that was pressed into a variable which I named “digit” and I then compared it against that variable as follows:

if type Char::IsDigit(digit)
      do something
end-if.

This works for what I am trying to achieve. Thanks for your help!