Help Convert to vb.net .net 3.5(VS 2008)
-
Wednesday, April 25, 2012 3:33 PM
Hello a create a extension method in C# .net 3.5 , with the help of this forum to catch the selection change in cells [msexcel 2007], and i like to now if it is possible convert this to vb.net vs2008?
This is the static method.
static class ExcelExtensions { public static IObservable<Excel.Range> WhenCellSelect(this Excel.Workbook WB) { var t= Observable.Create<Excel.Range>(observer => { Excel.WorkbookEvents_SheetSelectionChangeEventHandler handler = (Object sh,Excel.Range target) => { observer.OnNext(target); }; WB.SheetSelectionChange += handler; return () => WB.SheetSelectionChange -= handler; }); return t; }Thank's, sorry for my english
- Edited by carman68 Wednesday, April 25, 2012 3:40 PM
All Replies
-
Wednesday, April 25, 2012 4:49 PM
Hi,
Yes, it's possible to write your code in VB.NET instead of C#. Try asking your question in the VB.NET forum for help converting from C# to VB.NET.
Though your query can be simplified by using Observable.FromEvent or Observable.FromEventPattern.
- Dave
-
Wednesday, April 25, 2012 5:29 PM
Thank's Dave i try the other forum for the conversion.
in C# how to simplify? can you show how or point directions (i newbie in rx thank's).
carman
-
Wednesday, April 25, 2012 6:23 PM
Hi Carman,
It should look something like this, though I haven't tested it myself.
public static IObservable<Excel.Range> WhenCellSelect(this Excel.Workbook WB) { return Observable.FromEvent<Excel.WorkbookEvents_SheetSelectionChangeEventHandler, Excel.Range>( h => WB.SheetSelectionChange += h, h => WB.SheetSelectionChange -= h); }- Dave
-
Sunday, April 29, 2012 8:20 AM
Hi, Dave Thank's to point the direction, but i receved a
ArgumentException "Error binding to target method." with this StackTrace:
at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure) at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method) at System.Reactive.Linq.Observable.<>c__DisplayClass19c`2.<fromevent>b__19a(IObserver`1 observer) at System.Reactive.AnonymousObservable`1.<>c__DisplayClass1.<subscribe>b__0() at System.Reactive.Concurrency.Scheduler.Invoke(IScheduler scheduler, Action action) at System.Reactive.Concurrency.ScheduledItem`2.InvokeCore() at System.Reactive.Concurrency.ScheduledItem`1.Invoke() at System.Reactive.Concurrency.CurrentThreadScheduler.Trampoline.Run() at System.Reactive.Concurrency.CurrentThreadScheduler.Schedule[TState](TState state, TimeSpan dueTime, Func`3 action) at System.Reactive.Concurrency.CurrentThreadScheduler.Schedule[TState](TState state, Func`3 action) at System.Reactive.Concurrency.Scheduler.Schedule(IScheduler scheduler, Action action) at System.Reactive.AnonymousObservable`1.Subscribe(IObserver`1 observer) at System.ObservableExtensions.Subscribe[TSource](IObservable`1 source, Action`1 onNext, Action`1 onError, Action onCompleted) at System.ObservableExtensions.Subscribe[TSource](IObservable`1 source, Action`1 onNext) at ReactiveProgrammingConsole.InteropLab.Main() in D:\Metropolitano\Escalas\Excel_RX_events_C\Excel_RX_events_C\Program.cs:line 88</subscribe></fromevent>
I suspect that is in signature of method , the second parameter await a TEventArg and I am giving an Excel.Range, it is??
how to wrap the arguments of the excel workbook in TEventsAgs?
I call the method this way
try { WB.WhenCellSelect().Subscribe(cell => Console.WriteLine(cell.Row)); } catch(ArgumentException ex) { Console.WriteLine(ex.StackTrace); }
Thank's
carman68
-
Sunday, April 29, 2012 10:18 AM
Hi,
Try specifying the delegate conversion parameter:
public static IObservable<Excel.Range> WhenCellSelect(this Excel.Workbook WB) { return Observable.FromEvent<Excel.WorkbookEvents_SheetSelectionChangeEventHandler, Excel.Range>( h => h, // delegate conversion h => WB.SheetSelectionChange += h, h => WB.SheetSelectionChange -= h); }- Dave
- Edited by Dave Sexton Sunday, April 29, 2012 10:19 AM Forgot a comma
- Marked As Answer by carman68 Monday, April 30, 2012 1:06 AM
-
Monday, April 30, 2012 1:07 AM
Thank's Dave
apreciate the support
carman

