C# reference for VB

Hi!

I'd like to use some C# codes in my VB.Net 2002 project. I've been told to compile the C# code and reference it to VB unfortunately I really dont know how to. I have the C# project and I tried "Add reference", but it doesn't work.

I tried converting the C# code to VB but it did not work the way it does in C#.

Care to shove/kick me into the right direction?

[403 byte] By [Kaberto] at [2008-1-10]
# 1

Did you try a C# to VB converter? One is available at:

www.tangiblesoftwaresolutions.com

Otherwise, post the code here if it's not too lengthy and maybe someone can help out.

Solitaire at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Try http://converter.telerik.com/ works like a champ. You wouldnt want any of that ugly C# code in your project anyway.

DiverKas at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
As long as you have a compiled assembly for your C# code, you can use it in your VB.NET project. Use Add Reference + Browse tab and navigate to the compiled assembly.
nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

Reference are all in CLR language so can be used ! VB can use c# and vice versa with c++ or java

OmarAbid at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5

Thanks for th replies guys, but unfortunately I have tried converting the code via http://www.kamalpatel.net/ConvertCSharp2VB.aspx also through the given converters but it really doesn't work in VB.

I copied the exact C# code here ( http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2156764&SiteID=1 )and it worked but when I converted it, it didn't. I was advised to just make the C# code work in VB, ( http://www.vbdotnetforums.com/showthread.php?p=67859 ) I'd like to try hoping that C# codes in VB gets C# answers and not VB answers.

I tried the Add Reference + browse before and all I got was "A reference to ... could not be added. This is not a valid assembly or COM component. Only assemblies with extension dll and COM components can be referenced.

Kaberto at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
If the C# code references the same .Net versions as the VB code and the C# code contains no unsafe code, VB code equivalent to the C# code can be generated. Why don't you just compile the C# code as dll's and reference them from VB?
JohnWein at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7

Try this (this is the VB version of the original code produced by Instant VB):

Code Block

' Load in the images
Dim sQuery As String
Dim imageByteData As System.IO.MemoryStream
sQuery = "SELECT image FROM images"
Dim oConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Test App\Images.mdb;Jet OLEDBatabase Password=;")
oConnection.Open()
Dim oAdapter As OleDbDataAdapter = New OleDbDataAdapter(sQuery, oConnection)
Dim dtTable As System.Data.DataTable = New System.Data.DataTable()
dtTable.Clear()
Dim iNumberOfRows As Integer = oAdapter.Fill(dtTable)
If iNumberOfRows > 0 Then
PictureArray = New ArrayList()
Dim iRow As Integer = 0
For Each dtRow As System.Data.DataRow In dtTable.Rows
Dim bf As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim imageData As Byte()
imageData = CType(dtRow("image"), Byte())
imageByteData = New System.IO.MemoryStream()
bf.Serialize(imageByteData, dtRow("image"))
m_oPicturePreviewArray(iRow).Image = Image.FromStream(imageByteData)
iRow += 1
Next dtRow
Else
System.Windows.Forms.MessageBox.Show("No Rows Of Data")
End If

DavidAnton at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...