-
Notifications
You must be signed in to change notification settings - Fork 33
Proscriptions & C# isms
Benjamin edited this page Mar 14, 2020
·
6 revisions
What C# can't do that VB6 can
-
Optional ByRef
- There is no equivalent in C#. There are ways you can try to work around this, such as overloaded function signatures, etc, but, in general, try to refactor away from this generally considered bad programming practice.
-
With
- Convenient, but not supported by any language but VB6. In the majority of cases, a temp variable can be substituted, but in wider usage, the VB6 syntax allowed the use of this with functions that returned a value. This is harder to catch up to.
- In general, try to refactor away from the use of
With
when you decide to convert to VB6. It's tempting to simply let the converter do it, but you wont be happy with the variable name choice anyway. You'll just have to refacgtor it manually in the end to make the variable names make sense. Use the linter to detectWith
usage in VB6.
-
On Error
- Not available in C#. They use the
try ... catch ...
syntax. These are flagged in converted code and should be handled manually. Of course, many things that could only be handled in VB6 with error catching could be more efficiently done in C# without throwing errors, so there is that.
- Not available in C#. They use the
Some things to be aware of in C# that we make use of (2017 version)
- True classes. You will need to understand OO programming and you should have some working knowledge of C#.
- We chose WPF. While WinForms might be more congruent to VB6, it is largely unsupported. We wanted to be able to use the same higher end graphics that we had worked to implmeent in VB6, so WPF was the only real choice for us. VB6 are converted to XAML, and can be edited in the VS GUI.
- Extension Functions
- You can add a function to a class without changing the class itself. This is called an "Extension Function". We use these.
- We would have loved to use C#'s proposed "Extension Properties", and saved a lot of conversion, but they were not available yet.
-
using ...
- C# requires you to declare each module you want to use the functions of with ausing
statement at the beginning of the file. With VB6, public functions in public modules were accessible from anywhere. The simplest solution for this, of course, is to add ausing
statement for every module in your project into every file that is converted. This, of course, results in extra imports, but allows quicker turnaround. However, these extra imports can be cleaned up quickly and easily by a few keystrokes to reformat the file and optimize imports (^K^D on VS 2017).