Highlighted
Honored Contributor.
Honored Contributor.
1431 views

exposing .Net classes

Jump to solution

I have a Visual Studio 2013 - Visual COBOL Managed (can I just refer to it as Visual Cobol .Net?) program that I am using to convert a string data type to a decimal data type, using the "convert" function (ignoring validation for now).

Currently, I have a REPOSITORY with this:

    class convertClass as "System.Convert".

and in the procedural code, I am doing this:

   MOVE convertClass::ToDecimal(myString)  TO myDecimal.

What I want to know is how to do this using the alternate approach of using the $set ilusing directive so that I can do something like this instead:

  MOVE convert::ToDecimal(myString)  TO myDecimal.

I have tried it several ways ($set ilusing"System.Convert" and $set ilusing"System"), but I can't seem to get it to recognize System or System.Convert such that I can do this.

Thanks

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: exposing .Net classes

Jump to solution

Actually, the repository is no longer required in Visual COBOL. That is a holdover from Net Express.

In VC you use the type keyword to specify a class name.

You should be able to use:

   set myDecimal to type Convert::ToDecimal(mystring)

without specifying $set ilusing"System" because the System namespace is automatically included by default.

If you wish to do validation then you could instead use the TryParse method of the Decimal class.

  if not type Decimal::TryParse(mystring, myDecimal)

      move 0 to myDecimal

  end-if

Or you could insert a try catch block around the Convert statement.

Thanks.

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: exposing .Net classes

Jump to solution

I prefer to use the set statement but you can use move if you prefer but you must use the type keyword in front of the class name which is Convert (or System.Convert)

move type Convert::ToDecimal(mystring) to myDecimal

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: exposing .Net classes

Jump to solution

Actually, the repository is no longer required in Visual COBOL. That is a holdover from Net Express.

In VC you use the type keyword to specify a class name.

You should be able to use:

   set myDecimal to type Convert::ToDecimal(mystring)

without specifying $set ilusing"System" because the System namespace is automatically included by default.

If you wish to do validation then you could instead use the TryParse method of the Decimal class.

  if not type Decimal::TryParse(mystring, myDecimal)

      move 0 to myDecimal

  end-if

Or you could insert a try catch block around the Convert statement.

Thanks.

View solution in original post

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: exposing .Net classes

Jump to solution

Thanks, Chris.

Your "set" example above works, and the $set directive is not required to do this, since System is auto-included (and incidentally, thanks for the validation tip).

But, how would you code this using a MOVE statement instead of a set statement???

(Or, could you be implying that the MOVE statement and the set statement are not exactly equivalent and that this is one of those exceptional situations???)

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: exposing .Net classes

Jump to solution

I prefer to use the set statement but you can use move if you prefer but you must use the type keyword in front of the class name which is Convert (or System.Convert)

move type Convert::ToDecimal(mystring) to myDecimal

View solution in original post

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: exposing .Net classes

Jump to solution

Excellent!  Thanks!

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.