.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help converting C# to VB.NET

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
wouterbleumink
1393 Views, 8 Replies

Need help converting C# to VB.NET

Hello all,

 

I am a enthausiast and not a professional. I am used to wrting my code in VB.Net. Mostly this is not a problem as there are numerous C# to VB code-converters available on the web.

 

The code from the example in this article: Trough the interface: xref however does not convert correctly. For example the 'sub initialize' present's a problem for me.

 

Would it be possible for someone to post the VB.Net code for this topic?

 

Kind regards,

 

Wouter

 

 

8 REPLIES 8
Message 2 of 9

What's the problem you are having with the Initilize method?

 

Here's the stub of what it should look like:

Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize

      'your code goes here

End Sub

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
Message 3 of 9
Anonymous
in reply to: wouterbleumink

I always use this convertor. It's free and works like a charm.

 

http://converter.telerik.com/

 

Kind regards,

 

Irvin

Message 4 of 9

Thank you for your reply.

 

When converting the C# code, the sub Initialize looks like this:

 

 

Public Sub Initialize()
	Dim dm As DocumentCollection = Application.DocumentManager

        ' Remove any temporary objects at the end of the command

	dm.DocumentLockModeWillChange += Function(sender As Object, e As DocumentLockModeWillChangeEventArgs) Do
        If _ids.Count > 0 Then
            Dim tr As Transaction = e.Document.TransactionManager.StartTransaction()
            Using tr
                For Each id As ObjectId In _ids
                    Dim obj As DBObject = tr.GetObject(id, OpenMode.ForWrite, True)
                    obj.[Erase]()
                Next
                tr.Commit()
            End Using
            _ids.Clear()

            ' Launch a command to bring across our layers

            If Not _placeOnCurrentLayer Then
                e.Document.SendStringToExecute("_.XOFFSETCPLAYS ", False, False, False)
            End If
        End If
End Sub

 The line marked red in the code above causes my headaches. My knowledge of C# to VB is limited and i don't know how to convert it.

 

Can you help me?

 

Thanx in advance,

 

Regards Wouter

 

 

Message 5 of 9

Which version of VS (VB.NET) you use? VS2010 or VS2008? Since you are doing AutoCAD programming, I assume you use VS2008 with .NET3.x, or VS2010 targeting .NET3.x.

 

In this case, VB.NET does not has good support as C# to anonymous method, which looks like in C#:

 

SomeObject +=(o, e)=>{....};

 

or

 

SomeOject += delegate(o,e){....};

 

In VB.NET2008, you just

 

AddHandler dm.DocumentLockModeWillChange, AddressOf DocManager_LockModeWillChange

 

Then you write a separate method

 

Private Sub DocManager_LockModeWillChnage(sender as Object, e As DocumentLockModeWillChangeEventArgs)

    'Do whatever you need to do to handle the event

End Sub

 

Yes, some C# to VB.NET converter does not do a good job on this kind of Lambda/Anonymous function/method conversion. (this makes C# programmer looks having a bit more edge the VBer :-().

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 9

Norman's comments are correct, but since I was already doing it, and since figuring out what to move to a new function might be tricky, I have attached a text file with the code converted to VB.

Dave O.                                                                  Sig-Logos32.png
Message 7 of 9

Thank you Norman and Chiefbraincloud.

 

I am using VB2008..

 

I will try the code submitted tomorrow..

 

Thanx again.

 

regards,

 

Wouter

Message 8 of 9
Anonymous
in reply to: wouterbleumink
Message 9 of 9
Anonymous
in reply to: wouterbleumink

Here is the converter I generally use:

http://www.developerfusion.com/tools/convert/csharp-to-vb/

 

Developerfusion.com is a good website in its own right. The addition of the converter just makes it more valuable.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report