- Saves Valuable Time
- Trusted Accuracy since 2004
- 15-Day Money-Back Guarantee
Convert between VB.NET, C#, Java, C++, & Python, while saving countless hours of painstaking work and valuable time.
How to create setup file in visual studio 2019 for windows application step by step.Website: this video tutorial you will learn:c. SQL Server and the.NET Framework are based on different type systems. For example, the.NET Framework Decimal structure has a maximum scale of 28, whereas the SQL Server decimal and numeric data types have a maximum scale of 38. To maintain data integrity when reading and writing data, the SqlDataReader exposes SQL Server–specific typed.
Key Benefits
- Saves valuable time
- Accurate and comprehensive
- Safe - your code never leaves your machine
- Responsive customer support
- Numerous conversion and formatting options
- Easy to use
- 15 day money-back guarantee
- Helpful conversion comments
- Excellent tools for learning new languages
- Tens of thousands of lines converted per minute
Try the Free Edition
- Free
- High-quality conversion
- Limited conversion output
Purchase the Premium Edition
- 15-day money-back guarantee
- High-quality conversion
- Unlimited conversion output
Source Code Converters
Convert Between VB.NET and C#
- Instant C# (VB.NET to C#)
- Instant VB (C# to VB.NET)
Convert Between Java and C#
Convert Between C# and C++
Convert Between Java and C++
Convert Between VB.NET and C++
- VB to C++ Converter (VB.NET to C++)
- C++ to VB Converter (C++ to VB.NET)
Convert Between VB.NET and Java
- VB to Java Converter (VB.NET to Java)
- Java to VB Converter (Java to VB.NET)
Convert from Java to Python
3 Minute Overview of our C++ to C# Converter
3 Minute Overview of our VB to C# Converter (Instant C#)
Independent Reviews
View some independent reviews of our products.
Customers and Testimonials
Check out a list of some of our customers and our testimonials
Language Equivalents
Other Conversions
For information on converting from Objective-C to Swift and converting from VB6 to C#, click here.
Tips on Converting Between VB and C#
Want some tips on converting between VB and C#? Check out the article, 'Convert Between VB.NET and C#' in Visual Studio Magazine's Star wars episode 5 mp4. June 2005 issue by Dave Doknjas, President of Tangible Software Solutions. Click on the VSM logo to view the online version of this article:
Dr. Dobb's .NET Cast: Translating .NET to .NET
Click on Dr. Dobb's logo to listen to Tangible Software Solutions's President, Dave Doknjas, as he discusses converting .NET applications from VB to C#, or C# to VB with an overview of the challenges of translating .NET languages.
Home | Converters | Download | Purchase | Testimonials | FAQ | Support | Guarantee | Contact | About Us | Privacy | Site Map | Uninstall Instructions
Testimonials | Support | Uninstall Instructions | FAQ
Questions? Email Us | Facebook
Copyright © 2004 – 2021 Tangible Software Solutions, Inc.
Contents
If you have an important VBA code base you know how difficult it is to maintain it, not because VBA is inherently a bad or poor platform but because the developers are often either end-users not aware of good development practices or professional developers not skilled enough in VBA development who have learnt it on the job. In both cases, more often than not, you end up with poor quality source code.
There is other forces that make VBA development less appealing, as the pressure of software vendors like Microsoft who’d like to sell you not just Office but Office+Visual Studio and then promotes other technologies like .Net with languages such as C# and VB.Net. Just have a look at the evolution of the VBA editor design and capabilities since 10 years and you’ll understand that it does not benefit from fanatic development and promotion efforts.
It’s why you should avoid the headlong rush and restrict your VBA development efforts to the bare minimum: for new developments you should consider other languages and platforms like C# and VB.Net with the .Net framework as they seamlessly integrate with the Office suite, with little overhead compared to the direct integration of VBA, and give you access to a wealth of modern technologies.
But don’t be fooled by the FUD about the dangers of keeping a legacy VBA code base and do your due diligence: does the guy who suggest you a full migration will do it for free or is he paid for the job? 😉 A full migration may be a necessity: not because the platform is VBA but because the application is buggy, undocumented, out of control and using it creates a true operational risk, and this is true for any application and technology including the newest.
Then, if you have a VBA application that is working perfectly, is documented and controlled, an alternative to both the headlong rush and the full migration is the integration of .Net components with VBA, you then use a future-proof technology to develop new features and/or replace legacy features as you go along, avoiding the big-bang effect. Atomic email hunter.
So now you know what to do and right now I’ll show you how to do this seamless transition from VBA to greener pastures by implementing a simple API with three popular .Net languages: C# (the king), VB.Net (the prince) and C++/CLI (the Jack of all trades, master of none).
The .Net API we’re going to build is a basic market-data provider that uses the Yahoo finance API as its back-end.
The API provides 4 methods:
- 3 unitary methods: GetBid, GetAsk, GetCapitalization, for retrieving the bid price, ask price and the capitalization of a stock, respectively,
- a bulk method: GetValues, for retrieving any set of fields (check this list of available fields to have an idea of which data you can get).
The code is minimal, with no error handling, to avoid any distraction.
We’ll write usual C#,VB.Net and C++/CLI code with some COM stuff: the Guid attribute to uniquely identify our COM-visible types and the ClassInterface attribute to control the way the COM interface is generated: “None” means we use the first interface explicitly implemented by the class.
If you don’t want to write any code or command-lines you can download this ZIP archive where I’ve packaged: the source-codes, a CMD script that builds and registers the API, and a demo Excel spreadsheet with VBA code (in the “mYahoo” VBA module).
You should just have to run the CMD script with administrator privileges from a Visual Studio Command Prompt, open the sample spreadsheet and click the “Load“ button.
When it comes to selecting a language for .Net developmentC# is the default choice if you have no constraints because it was designed and is promoted as the flagship of the .Net framework. As such it benefits from a great development effort and a huge community.
Here is the C# implementation of our API: Vray 2 for sketchup 2015 mac.
We compile it using the CSC C# compiler:
“/target:library” asks CSC to generate a DLL rather than an EXE.
So we now have a “FinanceCS.dll” .Net DLL assembly.
In the .Net world VB.Net is your second choice if for any reason you have discarded C#. VB.Net is easier to grasp for VBA developers and can be an intermediate step on the road to full .Net applications: you won’t be distracted by a new language syntax and can concentrate on the .Net framework itself to get your productivity back quicker.
And this is what our API looks like in VB.Net:
As with C#, compilation is straightforward, this time using the VBC VB.Net compiler:
As you’ve guessed “/target:library” has the same meaning for VBC and CSC: generating a DLL assembly rather then an EXE assembly.
And we get a “FinanceVBNet.dll” DLL.
Why do I nickname C++/CLI the “Jack of all trades, master of none“?
“Jack of all trades” because it has the unique ability to talk to and be used by both native and managed components. It (almost) seamlessly mixes the two worlds in one place, what makes me consider C++/CLI as one of the most brilliant piece of software I’ve ever seen.
“Master of none” because C++/CLI is not your best choice for either .Net or native development:
- if you have no particular constraints and want a powerful language that integrates seamlessly with all the managed technologies (e.g. WPF) then your obvious choice is C#
- if you need high performance then you’ll go the native C++ way for your critical numerical code and let C# do the soft job
So, nowadays, C++/CLI is mainly pertinent as a great integration layer between the native and managed worlds (typically between C/C++ and C#): you’ll use it to build dumb wrappers, the plumbing that fills the gap between these two worlds.
C To Vb.net Convert
I’ve decided to use C++/CLI here for educational purposes:
- first this is the rare occasion to put side by side C#, VB.Net and C++/CLI codes, which should hopefully helps those who use one or two of these languages and want to discover another one,
- second, for those who had the occasion to develop Excel extensions with native C++, it will demonstrate how easy it is now to build them with C++/CLI,
- third it will illustrate how the use of a common platform, .Net, will make the 3 seemingly different versions of the API deployable and usable in a single manner.
So here is the C++/CLI creature:
Not too frightening, except some oddities like these “^” everywhere and the magic “cli” namespace.
We compile it using the CL C++ compiler:
“/clr:safe” is for generating a pure .Net assembly (by default CL generates native binaries while we want a CIL binary).
“/LD” asks CL to generate a DLL rather than an EXE.
This gives us our third DLL assembly: “FinanceCPP.dll“.
What is great with managed platforms like Java and .Net is that once you have your byte-code binaries you can use a single process to rule them all.
So here are the COM-registration commands for the 3 implementations of the API (you’ll need to run them with administrator privileges):
Some explanations:
- “/codebase” tells regasm to reference the assemblies full path into the registry, not only its name; otherwise your assembly should be put into the GAC which in this case is useless and would be pure overengineering (but sometimes, for assemblies shared by many applications, the GAC can be useful)
- “/tlb” tells regasm to generate and register a TLB file for the DLLs: a TLB file holds some metadata that will be consumed by the clients of our API to allow for a more user-friendly usage especially by allowing auto-completion in the VBA editor.
And if you try you’ll obtain this error:
Here is another post that explains how you can change RegAsm configuration to make it accept loading from the network.
Note that in a production context you should not have this issue because you typically first install the DLL on the local drive, e.g. in “C:Program FilesMy CompanyFinance Extensions“, and then register it from there.
Our API is now ready to get used by VBA.
Compiling and registering by hand is the best way to understand what is going on under the hood, but in a production environment you’ll probably use Visual Studio to edit your code, compile it, and register the DLLs.
You must configure 2 things in Visual Studio to get the same behavior:
- Make the .NET assembly COM visible so that the classes you create will be registered into the Windows registry: go to the library project’s properties, then the “Application” tab, then click “Assembly Information“, and finally check “Make assembly COM-Visible“.
- Register for COM interop: still in project’s properties go to the “Build” tab, then check “Register for COM interop“.
The first thing we need to do is referencing our 3 libraries TLBs:
go to the Excel VBA editor (shortcut: ALT-F11) and open the “References“ popup:
Then locate and select the “FinanceCS“, “FinanceVBNet” and “FinanceCPP” references:
You can now transparently use our YahooAPICS, YahooAPIVBNet and YahooAPICPP classes as if they were native VBA types.
Here is a basic example that retrieves and displays the bid price of Google using the C# implementation of the API:
(message for pedantic geeks: yes I know that As New is evil but I couldn’t resist ;))
Note: first call can be quite slow if you use IE automatic settings detection, so if you don’t need this feature disable it (see this thread for instructions).
Here is a more complete sample that you’ll find in the example spreadsheet in the “mYahoo“ VBA module:
As you see, whatever the language used, the objects declaration, instantiation and usage are strictly the same, you just use different classes: YahooAPICS, YahooAPIVBNet and YahooAPICPP.
Here is what you get when using the demo spreadsheet included into the archive attached with this article:
I hope this article has helped you realize that interfacing VBA and .Net is a relatively straightforward process: implement with the language you want, compile, register and enjoy!
But this is not all rosy with COM interop because as a universal layer of abstraction between different technologies it had to choose a common denominator, so there is features in .Net you can’t use with COM interop like non default constructors, methods overloading or static methods.
All these limitations are not critical and can be easily workaround keeping quality to a high level; you can check this article if you want more details on the design decisions you may have to take with .Net/VBA COM interop: How I Came to Love COM Interoperability.
Of course there is more to .Net development than this, but adding additional features like error-handling, logging, or graphical user interfaces, is much more convenient within the .Net environment (especially with Visual Studio which is a great IDE) than it is in the more limited world of VBA.
C# To Vb.net Code
If you have any question, issue or suggestion please feel free to let a comment, I’ll do my best to answer it in a timely fashion.