Translate C# to VC

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

  • 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.
  • Correction, the attach statement should probably be:
    attach new NuxIO.ValueEnteredEventHandler (OnValueEnteredEvent) to _NuxIO::ValueEnteredEvent
  • Verified Answer

    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.
  • 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
  • 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.
  • 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

  • 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?

  • 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
  • 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.

  • Verified Answer

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

    Many thanks for all.

    Best regards
    Alberto Ferraz