Highlighted
Absent Member.
Absent Member.
1261 views

IS keyword conversion

Jump to solution

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

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: IS keyword conversion

Jump to solution

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

View solution in original post

0 Likes
3 Replies
Highlighted
Absent Member.
Absent Member.

RE: IS keyword conversion

Jump to solution

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

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: IS keyword conversion

Jump to solution

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

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: IS keyword conversion

Jump to solution

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

0 Likes
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.