Help convert code piece from C# to VB.Net,

April 7, 2011 at 11:35:26
Specs: Windows XP
Anyone out there have the expertise to conver below code from C# to VB.Net, I'm using VS 2005. It's from another thread; here are the details:

I'm able to convert most of it but MyProject called "LogCodes" does not have a ".Properties" and my DLL is called: "Interop.EXTRA.dll"


This is for C# in VS2005.


Step 1) add the dll as a resource. To do this open the project, select the resources tab, select "add existing file" and add the DLL as a resource.


Step 2) Add the name of the DLL as a string resource.


Step 3) Add this code to your main form-load: (In this example my project is called "USBXpress_TestPanel", and the DLL file I'm using is "SiUSBXp.dll").


Code Snippet
if (System.IO.File.Exists(USBXpress_TestPanel.Properties.Resources.DLLName + ".DLL") == false)

{
System.IO.StreamWriter OutStream;
System.IO.BinaryWriter BinStream;
// Create the DLL file

OutStream = new System.IO.StreamWriter(USBXpress_TestPanel.Properties.Resources.DLLName + ".DLL", false);
BinStream = new System.IO.BinaryWriter(OutStream.BaseStream);
BinStream.Write(USBXpress_TestPanel.Properties.Resources.SiUSBXp);
BinStream.Close();
}

http://social.msdn.microsoft.com/Fo...


See More: Help convert code piece from C# to VB.Net,

Report •


#1
April 7, 2011 at 18:32:28
With the power of text find/replace:
If (System.IO.File.Exists(USBXpress_TestPanel.Properties.Resources.DLLName + ".DLL") == false) Then
  System.IO.StreamWriter OutStream  
  System.IO.BinaryWriter BinStream  
  ' Create the DLL file

  OutStream = New System.IO.StreamWriter(USBXpress_TestPanel.Properties.Resources.DLLName + ".DLL", false)  
  BinStream = New System.IO.BinaryWriter(OutStream.BaseStream)  
  BinStream.Write(USBXpress_TestPanel.Properties.Resources.SiUSBXp)  
  BinStream.Close()  
End If

How To Ask Questions The Smart Way


Report •

#2
April 8, 2011 at 06:44:45
Thanks for taking a shot at this Razor! Below code is real close (with a few adjustments), but still not correct in regards to "project" name. My project name is LOGCODES but it has no ".Properties.Resources.DLLName". Also tried "Me.", but no luck finding a properties option.

Currently it's going to error on "LOGCODES", how do you get to ".Properties.Resources.Interop.EXTRA.dll"?

Dim OutStream As System.IO.StreamWriter
Dim BinStream As System.IO.BinaryWriter
If (System.IO.File.Exists(LOGCODES.Properties.Resources.DLLName + ".DLL") = False) Then
' Create the DLL file
OutStream = New System.IO.StreamWriter(LOGCODES.Properties.Resources.DLLName + ".DLL", False)
BinStream = New System.IO.BinaryWriter(OutStream.BaseStream)
BinStream.Write(LOGCODES.Properties.Resources.Interop.EXTRA.dll)
BinStream.Close()
End If


Report •

#3
April 8, 2011 at 08:34:26
OK, here is the conversion for anyone interested, orriginally i missed the step of adding the file and string reference.
Completed code:

where rInterop_EXTRA is a string resource equaling the name of the DLL file.

Dim OutStream As System.IO.StreamWriter
Dim BinStream As System.IO.BinaryWriter

If (System.IO.File.Exists(My.Resources.rInterop_EXTRA + ".DLL") = False) Then
' Create the DLL file
OutStream = New System.IO.StreamWriter(My.Resources.rInterop_EXTRA + ".DLL", False) 'see resources for rInterop_EXTRA
BinStream = New System.IO.BinaryWriter(OutStream.BaseStream)
BinStream.Write(My.Resources.rInterop_EXTRA)
BinStream.Close()
End If


Report •
Related Solutions


Ask Question