converting C#.net code to VB.net

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
i've found an article on drag&drop that i could make very useful in vb applications but i can barely make out what the code is actually doing.

here's the article: http://www.codeproject.com/csharp/TestEmailDragDrop.asp

does anyone know of any programs that will translate (hopefully line for line) the C# code and convert it to VB code?
 
actually all i want to have it do is if you drag a file from your hdd (floppy, cd, flash drive, etc...) from the file system and drop it onto the form i'd like to know how to only get the file's (drive):\path\name.ext like a word document is dropped on the form it'd get the c:\...\my documents\wordfile.doc so if any one has any articles or anything, that'd be helpful
 
I don't know of any program that converts C# to VB, but I do speak a little C# so I converted the app manually. I've also added the code that handles file drops which wasn't present in the C# code.

To get the name(s) of the file(s) dropped, use the code e.Data.GetData(DataFormats.FileDrop) in the DragDrop event handler. This will return an array of strings containing the full path to the file(s).

Of course credit for the idea and Outlook Attachment code go to tgueth from CodeProject.com.
 

Attachments

  • TestEmailDragDropVB.zip
    17.2 KB · Views: 51
thanx Paszt that's exactly what i was looking for.

except on this line:
VB.NET:
fileNames = e.Data.GetData(DataFormats.FileDrop)

Option Strict On disallows implicit conversions from 'System.Object' to '1-Dimensional array of String'

now i know what that means, but i don't know the code to convert it to a 1-Dimensional Array, it would have been nice to have a Convet.To1dArray or something easy like that.

any idea's anyone?

nevermind, i just put it in a seperate module (as a function returning the path as a string) without option strict on and it works
 
Last edited:
How embarrassing. I forgot to turn on Option Strict, as all VB programmers should do. Shame on me :eek: .

Use this to convert the System.Object to a 1-dimensional array of string:
VB.NET:
Dim fileNames() As String
fileNames = CType(e.Data.GetData(DataFormats.FileDrop), String())
There were also a few other hidden type conversions so I've attached the corrected app.

Does VS2002 (or 2003) have an option to create all new projects with Option Strict On? (VS2005 does!)
 

Attachments

  • TestEmailDragDropVB.zip
    17.2 KB · Views: 73
it's ok paszt, i wont hold it against ya all you've done there is pointed out the fact that i'm not familiar with the CType function as i should be. also you didnt turn option explicit on either :p

but the revised program works wonderfully thanx
 
Back
Top