Highlighted
Outstanding Contributor.
Outstanding Contributor.
1806 views

Translate C# to VC

Jump to solution

Hello:

Can someone help me and translate these two C # instructions to Cobol?


_NuxIO.ValueEnteredEvent + = new NuxIO.ValueEnteredEventHandler (OnValueEnteredEvent);


Private void OnValueEnteredEvent (object sender, ValueEnteredEventArgs e)
{
If (e.Type == 2) ListBox.Invoke ((MethodInvoker)) => listBox.Items.Add ("IP:" + e.IPAddress + "RS232:" + e.Value)));
If (e.Type == 3) ListBox.Invoke ((MethodInvoker)) => listBox.Items.Add ("IP:" + e.IPAddress + "I8 Activated")));
If (e.Type == 4) ListBox.Invoke ((MethodInvoker)) => listBox.Items.Add ("IP:" + e.IPAddress + "I7 Activated")));
}

 

Thanks

Alberto Ferraz

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate C# to VC

Jump to solution
My colleague Ted John suggests the following as an equivalent for your method using Lambda expressions:

method-id OnValueEnteredEvent(sender as object, e as type ValueEnteredEventArgs)
if e::Type = 2
invoke listBox::Invoke(new Action(delegate invoke listBox::Items::Add("IP:" + e.IPAddress + "RS232:" + e.Value) end-delegate))
end-if
if e::Type = 3
invoke listBox::Invoke(new Action(delegate invoke listBox::Items::Add("IP:" + e.IPAddress + "I8 Activated") end-delegate))
end-if
if e::Type = 4
invoke listBox::Invoke(new Action(delegate invoke listBox::Items::Add("IP:" + e.IPAddress + e.IPAddress + "I7 Activated") end-delegate))
end-if
end method.

View solution in original post

Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Translate C# to VC

Jump to solution
Hi Chris:
Your sugestion works fine. It's all working.

Many thanks for all.

Best regards
Alberto Ferraz

View solution in original post

10 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate C# to VC

Jump to solution
The first one:

_NuxIO.ValueEnteredEvent + = new NuxIO.ValueEnteredEventHandler (OnValueEnteredEvent);

...should be something like this in COBOL:

attach new NuxIO.ValueEnteredEventHandler (OnValueEnteredEvent) to _NuxIO.ValueEnteredEvent
...assuming that _NuxIO.ValueEnteredEvent has already been define as an event.

We do not support lambda expressions as such in COBOL, but you can do the equivalent using anonymous methods,bracketed by the keywords delegate/end-delegate. However, I'm not 100% clear what you're doing in the call to ListBox.Invoke. If this is part of a working larger program, would it be possible for you to send it to me at robert.sales@microfocus.com?
Thanks,
Robert.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate C# to VC

Jump to solution
Correction, the attach statement should probably be:
attach new NuxIO.ValueEnteredEventHandler (OnValueEnteredEvent) to _NuxIO::ValueEnteredEvent
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate C# to VC

Jump to solution
My colleague Ted John suggests the following as an equivalent for your method using Lambda expressions:

method-id OnValueEnteredEvent(sender as object, e as type ValueEnteredEventArgs)
if e::Type = 2
invoke listBox::Invoke(new Action(delegate invoke listBox::Items::Add("IP:" + e.IPAddress + "RS232:" + e.Value) end-delegate))
end-if
if e::Type = 3
invoke listBox::Invoke(new Action(delegate invoke listBox::Items::Add("IP:" + e.IPAddress + "I8 Activated") end-delegate))
end-if
if e::Type = 4
invoke listBox::Invoke(new Action(delegate invoke listBox::Items::Add("IP:" + e.IPAddress + e.IPAddress + "I7 Activated") end-delegate))
end-if
end method.

View solution in original post

Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Translate C# to VC

Jump to solution
Hi Roberts:
Thanks for yor help.

What you sent me worked perfectly.

Now there is a small question in the command that should show on the screen the result of reading (invoke listBox :: Invoke (new Action (delegate invoke listBox :: Items :: Add ("IP:" + e.IPAddress + "RS232: E.Value) end-delegate)).
This instruction gives error. I already tried to change the + sign by & but it gives another error.
The purpose is to display in a screen field the result of the fields "and :: IPAddress" and "e :: Value".
Any instruction that works will do.
I'll keep trying to see if I can use the command.

Note: Thanks also extend to Ted.

Best Regards
Alberto Ferraz
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate C# to VC

Jump to solution
I think we got it slightly wrong in the previous reply. As you say, the + signs need to be replaced by &, but also e.IPAddress should be e::IPAddress, and e.Value should be e::Value.
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Translate C# to VC

Jump to solution

In Windows Forms i put like this:

invoke listBox::Invoke(new Action(delegate invoke listBox::Items::Add("IP: "&e::IPAddress&" - RS232: "&e::Value) end-delegate))

and works fine.

Now i try to put the same instruction in my original project in WPF and give an error in "invoke listBox::Invoke(..."

The error is: "COBCH1710: 'type System.Windows.Controls.ListBox' has no member with name "Invoke"".

Can you help me?

 

Thanks

Alberto Ferraz

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate C# to VC

Jump to solution

The ListBox class in WPF is not the same as the Winforms version of ListBox. Most of the WPF controls are programmed differently and are not compatible between the two. What is it that you are trying to do? It appears like you are trying to fill the Listbox using a background thread or Async callback, is that correct?

It looks like in WPF you would use the Dispatcher.Invoke. Take a look at the link here and let me know if this is what you are attempting to do?

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Translate C# to VC

Jump to solution
Hi Chris:

It appears like you are trying to fill the Listbox using a background thread or Async callback, is that correct?
It´s correct. What I really need is to "show" what I get in a label, textbox or listbox.
I even programmed it into a label-type field.
The listbox in windows form appears because I tried to adapt the source of the API provider to realize its operation.

Regarding the link I think that the example defines what I need since the error that gives me in the execution is the same.

Thanks
Alberto Ferraz
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate C# to VC

Jump to solution

I have added a demo program that I wrote a while ago which updates a textbox on the UI thread from within a background thread using the Dispatcher.BeginInvoke method.WPFupdateUI2.zip

I hope this points you in the right direction.

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Translate C# to VC

Jump to solution
Hi Chris:
Your sugestion works fine. It's all working.

Many thanks for all.

Best regards
Alberto Ferraz

View solution in original post

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.