Neil_Willby Absent Member.
Absent Member.
1124 views

C# to VC Class

Jump to solution

Hi, is there any documentation on how to convert below C# into VC class?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aladdin.HASP;
namespace HaspLogin
{
public class login
{
public static Boolean check()
{
HaspFeature feature = HaspFeature.ProgNumDefault;
feature.SetOptions(FeatureOptions.IgnoreTS, FeatureOptions.Default);

string vendorCode =
"iOa2Wamd86sr/OMWsaak5l8iRdqFvHGr6pLCIKVMo8TreGxm4PQiUAsLcUgXNbdNzexvu6ZouLUorzGq" +
"LysvIDsplUEdF9iB1B7eFEAVkonVJeLlS9SPWeeMOSx9GSrIC7EyqIcyQJ77uVdrNAvVp0UGitNJZuKH" +
"OcpPqfXn6o1c2VZmkG/mSxyIEISent8QyrO6jNxB0W9AYc+yrTTJRZ1e7rZmVI6b1HSEPiJQiHwLhLJF" +
"wiu7fetR6AWI6A4a72ugZjZCDP154c8cNhopUfeYemH4088CFT56x4YpBWFI7G9OKBDAqdV1NxDLBjxL" +
"/h/hKnbEbOt6yGbzadWY0d2VsjPzktybk7bQKA/XRyxKS2k4xNgeE1zK2yZjsBqXamqCp5uEXnF21uC6" +
"7zAIzBWiyuWSYPykiFgNJvUas10ynFdSFLMkZolWswFyHNRNkmqI2+4EnDx4cJ5kB5CpFwC3rhu0YjRF" +
"5g0KDUSpzBnpI8wML3CwaVhiThPKJO9C6E43/gXcbBV9y+JgxBZUBLi5CLFPutow554GmH8wm2jcZ66E" +
"a0qKUtkgY3vr4buarI4pcc7k9q4yu000daT0ff/YTeYDgjLW5D4UARmpfc038wzaTiE0Ed16AhaOy4p8" +
"2wYuuw71GwBraLdvYUWSzWty157xSyp0pEU2nq6Kjnle4d/W44KRllsukE4AmCHi088TvcF2at+vSghv" +
"2PomnllXVjMmXA==";

Hasp hasp = new Hasp(feature);
// convert vendorcode to byte array
byte[] code = ASCIIEncoding.Default.GetBytes(vendorCode);
HaspStatus status = hasp.Login(code);

if (HaspStatus.StatusOk != status)
{
return false;
}
else
{
return true;
}
}

}
}

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: C# to VC Class

Jump to solution
Sorry, I missed that you had the static modifier in your C# code.

The recommended way of marking a method as static is to write static before the full stop after the method signature definition. For example:

```
method-id check() returning return-value as condition value static.

end method.
```

Just to be clear, you did have static in your C# code, so that is why you also need it in your COBOL version. Marking a method as static allows you to call the method without creating an instance of the class. This is fine if you don't intend to declare any non-static data in the class and use it within the method.

If you want to call a non-static method of a class, you would first need to instantiate it.
E.g.
```
procedure division.
declare loginInstance = new HaspLogin.login()
set checkResult to loginInstance::check()
.
```
0 Likes
5 Replies
Micro Focus Expert
Micro Focus Expert

RE: C# to VC Class

Jump to solution
Hi Neil,

Something along the lines of the code below:
or correctly formatted here: hastebin.com/igetewasod.cobol

Note that in COBOL, the namespaces can be imported via project properties so, not all of them are necessary. If a namespace is not imported, you should get a smarttag or light bulb suggesting to import the namespace into your project.

$set ilusing(System)
$set ilusing(System.Collections.Generic)
$set ilusing(System.Linq)
$set ilusing(System.Text)
$set ilusing(System.Threading.Tasks)
$set ilusing(Aladdin.HASP)

class-id HaspLogin.login

method-id check() returning return-value as condition-value.
declare feature = type HaspFeature::ProgNumDefault
invoke feature::SetOptions(type FeatureOptions::IgnoreTS,
type FeatureOptions::Default)

declare vendorCode as string = "..........." &
"..........."

declare hasp = new Hasp(feature)
*> convert vendorcode to byte array
declare #code = type ASCIIEncoding::Default::GetBytes(vendorCode)
declare #status = hasp::Login(#code)

if type HaspStatus::StatusOk <> #status
set return-value to false
else
set return-value to true
end-if
end method.

end class.
0 Likes
Neil_Willby Absent Member.
Absent Member.

RE: C# to VC Class

Jump to solution
Thats great many thanks I'll give it a go
0 Likes
Neil_Willby Absent Member.
Absent Member.

RE: C# to VC Class

Jump to solution
Hi, well i got it working but only after i made the following changes.

To make "check" visible to the calling program i had to add "static" and "end static" can you pls advise why this is?

I didnt see this happening in C# so why do I have to add it in Cobol or is there another way?

static.
method-id check() returning return-value as condition-value.

end method.
end static.
end class.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: C# to VC Class

Jump to solution
Sorry, I missed that you had the static modifier in your C# code.

The recommended way of marking a method as static is to write static before the full stop after the method signature definition. For example:

```
method-id check() returning return-value as condition value static.

end method.
```

Just to be clear, you did have static in your C# code, so that is why you also need it in your COBOL version. Marking a method as static allows you to call the method without creating an instance of the class. This is fine if you don't intend to declare any non-static data in the class and use it within the method.

If you want to call a non-static method of a class, you would first need to instantiate it.
E.g.
```
procedure division.
declare loginInstance = new HaspLogin.login()
set checkResult to loginInstance::check()
.
```
0 Likes
Neil_Willby Absent Member.
Absent Member.

RE: C# to VC Class

Jump to solution
Yep thats it thanks, makes sense now.
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.