IS keyword conversion

Hi :)

I have a code when I use the IS keyword, in C#, and I would be convert that code to Visual Cobol, how I can make this ?

see the code:

private static System.Boolean IsNumeric(System.Object Expression)
{
if (Expression == null || Expression is DateTime)
return false;

if (Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean)
return true;

try
{
if (Expression is string)
Double.Parse(Expression as string);
else
Double.Parse(Expression.ToString());
return true;
}
catch { }
return false;
}

Thanks

Alexandre Bencz

  • Verified Answer

    Hi,

    Try the instance of syntax. Soemthing like:-

              if lnk-obj instance of type System.Int32

                  display "I have been passed a System.Int32"

              end-if

    should do what you want.

    Regards

    David

  • I found one more question... how I can make the returns, in Try/Catch...??

  • Hi,

    We support try catch end-try in COBOL. However I think the catching of an exception is not the best performing way to do this.

    I would use the TryParse method. Something like:-

          method-id CheckDouble static.

          local-storage section.

          01  ls-double          comp-2.

          procedure division using lnk-obj as type System.Object

                  returning lnk-res as condition-value.

              if lnk-obj instance of type System.String

                  display "I have been passed a System.String"

              end-if

              set lnk-res to type System.Double::TryParse(lnk-obj as type System.String , ls-double)

          end method.

    The trycatch method will work but if your going through the code lots of times it may be expensive in performance terms of you have to catch lots of exceptions.

    Regards

    David