0

I've used Teleflex, developerfusion, and SharpDeveloper, and all these, to convert C# to VB, but as most know, there are always errors, and modules left out, and such.

Does anybody know of a good VB editor, preferably freeware, and can handle translated VB and offer suggestions to correct it for you?

Visual Studio underlines things and offers suggestions on some things, but other things it just underlines and leaves you to the guesswork, which doesn't help a non-coder like me.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Jason Weber
  • 5,653
  • 6
  • 40
  • 73
  • 3
    They're not that far from each other.. do it your self ? – f2lollpll Feb 02 '12 at 15:44
  • If you have a compiled version of the code you are trying to translate you can use Reflector to switch languages. It will give you ugly variable names but it will be a valid translation. – Justin Feb 02 '12 at 15:45
  • @Justin, This will generally work, but will be a nightmare if obfuscation is used. – Brad Feb 02 '12 at 17:10
  • 1
    @Brad, Obfuscation would be an issue if it wasn't your code. Since he has the original source code in C# he would have to obfuscate it himself which would be retarded in this case. – Justin Feb 02 '12 at 18:00
  • @Justin, So would compiling it, when the source is available. I just mentioned it so he wouldn't waste all day trying to build, and inspect with Reflector. – Brad Feb 02 '12 at 18:17
  • 1
    So why would you want to convert C# to VB in the first place? – RQDQ Feb 02 '12 at 20:18
  • 1
    @RQDQ, There are plenty of possible scenarios where one may want to do this. That isn't the question here. – Brad Feb 02 '12 at 20:31
  • 1
    @Brad - I still think it's a valid question. Maybe a better way to ask it is "Why do you want to convert C# to VB in this case? Is it because you only have VB talent in house?" – RQDQ Feb 02 '12 at 20:38
  • Hey fellas. Thanks for responding. It's just that I have a multilingual website, and I finally found a solution that adds querystrings for languages that fits in with my VStudio asp.net 4.0 coding. The only problem is that the solution is in C#. It runs great when I run the C# in my VS, but when I try to convert it to VB, things get screwed up. I'm in the robotics and automated engineering field, and we're small and just starting out. Maybe in a year, I'll be able to hire a full time programmer, but until then, I'm doing it and I'm having fun learning, mostly thanks to people here. – Jason Weber Feb 03 '12 at 00:28

4 Answers4

4

Non-coders shouldn't be translating C# to VB.

No code translator will take care of everything for you. Even if it works programmatically, there are design patterns and code standards that are different for each language. Hire a programer.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • 1
    Good point about using good patterns and standards for VB. Even if automatic translation gives no error, a programmer should validate the code anyway. – Meta-Knight Feb 02 '12 at 15:59
  • Imports System Imports System.Web.UI.WebControls Partial Public Class MasterPage Inherits System.Web.UI.MasterPage Protected Sub Page_Load(sender As Object, e As EventArgs) End Sub Protected Sub RequestLanguageChange_Click(sender As Object, e As EventArgs) Dim senderLink As LinkButton = DirectCast(sender, LinkButton) End Sub Private Function ApplyCultureToUrl(RawUrl As String, Command As String) As String Response.Redirect(ApplyCultureToUrl(Request.RawUrl, senderLink.CommandArgument)) End Function End Class – Jason Weber Feb 02 '12 at 16:59
  • VS keeps telling me that senderlink is not declared. It may be inaccessible due to its protection level. It gives me options to change senderlink to Hyperlink, generate method stubs, property stubs, a separate class ... I've tried all of the above, and they still spit out more errors. That's why I was just looking for a little VB help. – Jason Weber Feb 02 '12 at 17:02
  • 3
    @JasonWeber: You should ask a new question for this. – Meta-Knight Feb 02 '12 at 17:09
  • Thanks Meta ... I suppose I will after a couple of more tries. – Jason Weber Feb 03 '12 at 00:29
3

No. And it's not always possible to convert C# to VB. Some features of C# have no equivalent in VB.

  • Unsafe code (e.g. pointers)
  • Iterators (yield)

Conversely some features of VB have no equivalent in C#.

Why do you need to convert the code anyway? What's the business case?

Community
  • 1
  • 1
MarkJ
  • 30,070
  • 5
  • 68
  • 111
  • Mark, I found a solution to the multilingual querystrings that I need for my multilingual website. IT's written in C#, but when I plug is solution into my Vis Studio, it works perfectly. But my website is in VB, and when I try to translate, things get screwed up. It's only 4 small pages with maybe 10-15 lines of code per page. I'm in the robotics and automation industry, and maybe in a year, I'll be able to hire a full time programmer, but until then, I'm doing it myself and I'm having fun learning thanks to people in this forum. – Jason Weber Feb 03 '12 at 00:31
  • And thank you Mark, that was good information about the itereators, and static/shared being relatively similar in many instances. And actually, your link led to me finding the Asynchronous VS 2010 addon, which is probably still in beta, but will be very helpful. I appreciate you taking the time to respond! – Jason Weber Feb 03 '12 at 00:54
  • If this C# code is really that small, it should take only a day or so to convert it to VB. You could consider a contractor, or a development firm? Or investing some more of your own time in learning C# (if you *have* the time!). [This question](http://stackoverflow.com/questions/3415581/how-do-i-tune-up-my-c-sharp-skills-when-i-have-spent-the-last-decade-coding-in/3416358#3416358) is about learning C# when you know VB – MarkJ Feb 03 '12 at 08:53
  • Hey, thanks for the link, Mark -- I appreciate that and bookmarked it. I'll have the time, because I find programming so interesting and honestly, fun. I wish I had a fraction of the knowledge you and a lot of others had, and that's why I love reading this forum and links like the one you posted. Thanks again! – Jason Weber Feb 05 '12 at 01:12
  • It's just frustrating in a sense, because I never planned on learning a language. And had I known more in the beginning, I would have studied both more. But at the time, all I really knew that existed was VB. Live and learn! – Jason Weber Feb 05 '12 at 01:17
1

VB and C# are different langages, so even the best translator in the world will miss some things. The person doing the translation shouldn't be a "non-coder" and should know at least some VB, so when a compile error is shown, he knows what to do with it, or at least knows how to search on the web (or ask on SO) to know how such part of code can be translated to VB.

Meta-Knight
  • 17,626
  • 1
  • 48
  • 58
  • Thanks for the responses .... I mean, that's the problem with starting off with a smaller company who doesn't have the resources to allocate to hiring a full-time programmer. That's why I'm learning a lot of this on my own. I have learned a lot on here, and I'd like to learn more. I was just wondering if coders used a program I was unaware of, or if they really just do everything by hand in notepad, as many have suggested. – Jason Weber Feb 02 '12 at 16:58
  • 3
    Notepad? No. You would use a translator as you mentioned, and then you copy this code in Visual Studio and fix the problems with the translated code there. – Meta-Knight Feb 02 '12 at 17:08
  • @JasonWeber: The only people working with any of the .Net languages using Notepad are morons. VS 2010 Express is free... http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express – NotMe Feb 02 '12 at 20:20
  • Thanks Chris. I purchased a license for Visual Studio 2010, so I have it. Actually, I think Visual Studio should have their own built-in translator for VB/C# that should be more accurate than any online freeware, but that makes way too much sense, which is probably why they don't do it. I'm sure I'll figure it out with enough editing/uploading/refreshing-editing/uploading/refreshing, etc. .... – Jason Weber Feb 03 '12 at 00:34
1

Although vb.net and C# are both designed around the same .net framework, and consequently feature very similar features that work mostly the same way, many corner cases are handled differently by the two languages. While one could argue ad nauseum about whether a statement like myStruct = new myStructType(someParams) should affect the value of myStruct before the constructor completes (in C#, it does not; in vb.net, it does), and it's probably good to avoid designing code around corner cases, it's doubtful that any translator--much less a freeware one--will detect all of the corner cases and ensure that code which (possibly accidentally) relies upon them will still run correctly.

supercat
  • 77,689
  • 9
  • 166
  • 211
  • Thanks Supercat. I mean, I just don't like the talk about "non coders shouldn't be programming". I mean, I don't tell a sales representative or a marketing analyst that since he/she doesn't have a degree in mechanical engineering, he/she shouldn't be managing accounts in the robotics and advanced automated engineering. I (try to) help the person out and work with him/her. Thanks for your input, though, supercat. I appreciate it, and I'm sure I'll get it figured out through heuristic trial and error. – Jason Weber Feb 03 '12 at 00:53
  • @JasonWeber: One difficulty with many programming languages and frameworks, including .net, is that it's sometimes very easy to make things that "almost" work, but have some vexing problems which can't be resolved without major rework. I'm not sure what the best way is to learn to recognize what approaches are structurally sound and what approaches will be structurally problematic. – supercat Feb 04 '12 at 21:17