How do I convert this csharp code to vb.net? (anonymous methos)

I have a task of converting a class to vb.net (mine is not to ask why, just to ask how high!)

The following snippet below has me stumped.

What I need to do is come up w/an acceptable conversion.  I need an experts expert!

500 points to whomever can convert the below code to vb.net...

_oQueue.Send(delegate(object dummy)
            {
                InitializeStateMachine(oinitialstate);
            }, null);

Open in new window

louisiana_bluesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kevin CrossChief Technology OfficerCommented:
Here is an example of delegates in VB.NET:
http://www.developerfusion.com/article/5251/delegates-in-vbnet/
0
Kevin CrossChief Technology OfficerCommented:
Basically:

Delegate Sub MyDelegate(ByVal dummy As Object)

Then in your original code

Dim del As New MyDelegate(AddressOf InitializeStateMachine)
_oQueue.Send(del, null)
0
ITHelper80Commented:
_oQueue.Send(Function(ByVal dummy As Object) Do
    InitializeStateMachine(oinitialstate)
End Function, Nothing)

However VB does not support anonymous methods/lambda expressions with a statement body

Here is a sweet convertor I use all the time.
http://www.developerfusion.com/tools/convert/csharp-to-vb/ 
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Kevin CrossChief Technology OfficerCommented:
Very nice.  I miss typed null --> should be Nothing.  Like ItHelper80's converter.  Have to add that to my favorites.
0
louisiana_bluesAuthor Commented:
I understand that vb does not support anonymous functions.  What I am looking for is a *close as possible* vb.net conversion...whether by naming a function and calling it or whatever.

I belive mwvisa is very close, but he doesn't state specifically what the solution is.  Could you do that?  Then I can award you the points!

And yes, I am well familiar with that csharp conversion link--I'd bee screwd if I had to convert the code line by line! ;-)
0
louisiana_bluesAuthor Commented:
What I mean mvisa is that something is missing.  When I copy and paste your sollution into the class I get errors.  Could you go the extra dollar and convert the two lines of code completely to vb?
0
Kevin CrossChief Technology OfficerCommented:
I was suggesting using Delegates.  The tricky part is you can use the Invoke method to pass the variable to the delegate, but in your code you have to pass the delegate itself to the send method.

http://www.codeproject.com/KB/vb/Delegate.aspx

Is InitializeStateMachine a method you have defined in this class.  I have not used the StateMachine class before, so this might be part of that but just curious as that is the missing part.  The AddressOf piece of the delegate instantiation calls to the actual implementation method that has same signature as delegate declaration.

Therefore, an InitializeStateMachine sub with parameter of Object must exist already.
0
louisiana_bluesAuthor Commented:
Hey Visa:

It's two lines of code.  I have no clue what you are spaking of.  If you could just convert those two lines of code into acceptable vb, then I will give you the points!  I can't seem to get that last important part....
0
louisiana_bluesAuthor Commented:
I am also a visual woman...so it helps me understand something when I *see* code that is working...
0
Kevin CrossChief Technology OfficerCommented:
Please provide the remainder of the C# code...

Still have question on:
"Is InitializeStateMachine a method you have defined in this class?"
0
louisiana_bluesAuthor Commented:
Hey Visa:

Yes, InitalizeStateMachin is a function iin the same class as the code you see.  There's really not any other code that is relevant to the above anon function---just a definition of the _oQueue object (which is a Queue).

Hope this helps!
0
louisiana_bluesAuthor Commented:
From what I've read one should be able to replace the anonymous function with a real function, then mimic the rest of it.  Of course, the 'mimic the rest of it' leaves me stumped!

If you do name a function, just call it MyAnonymousFunction so we are both on the same page.  And Thank you so much!
0
louisiana_bluesAuthor Commented:
Well, haven't heard from anyone so I'll go ahead and post more code--though once you see it you'll understand it has nothing to do with the question, and thus is just filling up another question w/confusing posts for an expert who would know the answer except for wading through all of the non-answer answers.

You can see all the relevant code below.  I need to replace the anon function w/a named one...The IntializeStateMachine is just a function in the class.
        // Used for queuing events.
        private DelegateQueue queue = new DelegateQueue();
 
 
        protected override void Initialize(State initialState)
        {
            queue.Send(delegate(object dummy)
            {
                InitializeStateMachine(initialState);
            }, null);
        }

Open in new window

0
Kevin CrossChief Technology OfficerCommented:

'Used for queuing events.
Private queue As new DelegateQueue()
Private Delegate Sub InitStateDelegate(ByVal dummy As Object)
 
Protected Overrides Sub Initialize(State  initialState)
    Dim delegateInitState As InitStateDelegate
    delegateInitState = AddressOf InitializeStateMachine
   
    queue.Send(delegateInitState, initialState)
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kevin CrossChief Technology OfficerCommented:
That is about the extent of my understanding of the delegate situation you are dealing with here.  If you need further assistance you can use the request attention button to draw in higher ranked experts in this arena.
0
louisiana_bluesAuthor Commented:
Well visa, I'm going to give you the points, since you are the ONLY one who even responded, and (I'm assuming your code works--I just read you last message, and it seems as if you don't have confidence in this?  Either way you get the points, but could you tell me if you know this works or if it doesn't?  And why it wouldn't work?  Now I'm worried...
0
Kevin CrossChief Technology OfficerCommented:
The only reason I don't have confidence in it is that I don't have the DelegateQueue class on my system; therefore, I could not compile and test that this is indeed what you are needing.  From what you showed me and that I know of the DelegateQueue, it takes a delegate method as its argument.  The send method takes delegate and then an object array for the parameters to pass to that function/sub.

I put the code above in the correct places...just makes me feel better when I actual can say I compiled the code and this is what you will get.  Since I didn't do that, I am just being honest with you as to not waste any time getting more experts involved who may have this class already setup and working...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.