Help in translation

95se5m

Member
Joined
Nov 29, 2004
Messages
21
Location
NE Pennsylvania
Programming Experience
3-5
I have a bit of code.

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Value = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]And[/COLOR][/SIZE][SIZE=2] m_AutoRotateTimer [/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]m_AutoRotateTimer = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Timers.Timer(m_IncrementFrequency)
m_AutoRotateTimer.Elapsed += [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Timers.ElapsedEventHandler([/SIZE][SIZE=2][COLOR=#0000ff]AddressOf[/COLOR][/SIZE][SIZE=2] IncrementTransisionSegment)
m_AutoRotateTimer.Start()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE]

In VB.net 2005 SP1 this line of code:
m_AutoRotateTimer.Elapsed += New System.Timers.ElapsedEventHandler(AddressOf IncrementTransisionSegment)
will not work, it's complaining about not calling an event directly and wanting a RaiseEvent. Can anyone tell me how to modify this line to make it work? It's a bit of code I need to port from c#, works peachy in c#.

Help please...
Jim
 
Wouldn't you know, 5 minutes after posting this I finally found my answer on some obscure web site toting information about a how to book.

VB.NET:
[SIZE=2][COLOR=#0000ff]
AddHandler[/COLOR][/SIZE][SIZE=2] m_AutoRotateTimer.Elapsed, [/SIZE][SIZE=2][COLOR=#0000ff]AddressOf[/COLOR][/SIZE][SIZE=2] IncrementTransisionSegment
[/SIZE]

This is the equivilant code, and after a few adjustments, it works like a champ.

Thank you though for those of you who may have been searching for an answer while I typed this.

Jim
 
Which converter? *curious*

Also, whether or not syntax is more or less attractive in C# is probably an "eye of the beholder" thing.. I personally find VB.NET messy, inconsistent and superfluous. C# by comparison, is much neater, simple, more elegant and internally consistent.. But as noted, personal preferences abound ;)
On the specific case of events and delegates, i definitely prefer C#'s
VB.NET:
obj.Event += new EventHandler(nameOfHandleMethod)

To AddHandler ... for the same reasons that I prefer string.Substring(...), to Mid(string, ...)
 
Which converter? *curious*

Also, whether or not syntax is more or less attractive in C# is probably an "eye of the beholder" thing.. I personally find VB.NET messy, inconsistent and superfluous. C# by comparison, is much neater, simple, more elegant and internally consistent.. But as noted, personal preferences abound ;)
On the specific case of events and delegates, i definitely prefer C#'s
VB.NET:
obj.Event += new EventHandler(nameOfHandleMethod)

To AddHandler ... for the same reasons that I prefer string.Substring(...), to Mid(string, ...)


Well, you are right in the eye of the beholder, I prefer vb just because it's what I know, and I don't mind the minor differences. BTW we have string.substring as well. :p

Anyway, the converter I used was http://www.kamalpatel.net/ConvertCSharp2VB.aspx

if you know of a better one I am all ears... That one doesn't handle if-then-else statements very well either.
 
Back
Top