-2

I followed a walkthrough of a sync framework 2.1 sample and it works fine. But it's written in C# and I want to port it to VB. I came to the following line which I have had a hard time translating:

in the static Main of c#:

((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);

later on there is a handler written as:

 static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
    {
        // display conflict type
        Console.WriteLine(e.Conflict.Type);

        // display error message 
        Console.WriteLine(e.Error);
    }

how should I translate the first line to VB?

I tried the auto translators which give me two results (both fail to compile)

AddHandler CType(syncOrchestrator.LocalProvider,SqlSyncProvider).ApplyChangeFailed, AddressOf Me.Program_ApplyChangeFailed

and

DirectCast(syncOrchestrator.LocalProvider, SqlSyncProvider).ApplyChangeFailed += New EventHandler(Of DbApplyChangeFailedEventArgs)(Program_ApplyChangeFailed)
Ben Quan
  • 773
  • 11
  • 25
  • What part did the dozens of c# to vb code converters on google failed to translate for you? – Mystra007 Jun 16 '15 at 02:29
  • It's the first thing I tried. It translates to: DirectCast(syncOrchestrator.LocalProvider, SqlSyncProvider).ApplyChangeFailed += New EventHandler(Of DbApplyChangeFailedEventArgs)(Program_ApplyChangeFailed) But that gives an error. – Ben Quan Jun 16 '15 at 02:31
  • What was the error? The AddHandler / AdressOf method should be working. – Mystra007 Jun 16 '15 at 02:42
  • The conversion using DirectCast and leaving the "+=" operator in is definitely wrong - the first one using AddHandler looks perfect. What is the compile error? – Dave Doknjas Jun 16 '15 at 04:25
  • OK yes finally got it to work with: AddHandler CType(syncOrchestrator.LocalProvider, SqlSyncProvider).ApplyChangeFailed, AddressOf Program_ApplyChangeFailed Thanks – Ben Quan Jun 16 '15 at 15:22

1 Answers1

0

Finally got it to work with:

AddHandler CType(syncOrchestrator.LocalProvider, SqlSyncProvider).ApplyChangeFailed, AddressOf Program_ApplyChangeFailed
ryanyuyu
  • 6,366
  • 10
  • 48
  • 53
Ben Quan
  • 773
  • 11
  • 25