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
Solved! Go to Solution.
Solved by chiefbraincloud. Go to Solution.
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
I always use this convertor. It's free and works like a charm.
Kind regards,
Irvin
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
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
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.
Thank you Norman and Chiefbraincloud.
I am using VB2008..
I will try the code submitted tomorrow..
Thanx again.
regards,
Wouter
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.