What a C# Coder Should Know Before They Write VB

NOTE: I’ve updated this post because it shifted from its different intent, needed a new preamble, etc. You can find it here

I just had an e-mail exchange with someone looking for a VB lead in Colorado Springs. I think they are going to have trouble filling it with an existing VB expert, and it occurred to me that someone who had led a successful VB 6 -> C# project could fit the bill, if they knew some key things about VB. I told the recruiter I thought the right person with a C# background and the right (respectful) attitude could be a good fit with two weeks work. But in the back of my mind I’m thinking “what resource could she possibly access during those two weeks.”

I am sold on the concept of polyglot programming and think every C# coder should know enough VB to do Office, late binding, and XML work in VB. That’s not what I’m talking about. Those should be wrappers and really the quality of code doesn’t matter.

I’m talking about embracing the language enough to lead a team, and I’m assuming there’s honesty on all sides so the C# coder is admitting they are growing and learning. The framework is so core to what we do that it doesn’t make sense to demand one language or another. But it does make sense if your crossing over in either direction to embrace the elegance of the language you’re going to work in.

Hopefully this can be a dialog as I’m sure I won’t catch everything.

1) Get over the respect thing or quit before you start. VB is a great language.

2) Obviously stop trying to name fields the same as properties with different casing. VB matches case to the declaration, so that’s the only place you care.

3) You type less-characters, or perhaps the same as C#. Spend enough time in the IDE with auto-complete and Intellisense to accomplish this. I’m really sorry about the Ctl-Enter thing, but you can always use a space as VB will generally remove it if it’s wrong. (By the Ctl-Enter thing, I mean that you can’t just hit Enter to accept Intellisense. You must hit Ctl-Enter, or space or some other punctuation).

4) VB is very good at re-indenting and re-spacing for you

5) Switch the Intellisense tab to All. Visual Basic has a Common and an All tab for Intellisense. C# does not make this distinction so the All tab is likely to be most comfortable for a C# coder. The Common tab may leave you wondering where some method or property you need is located.

6) Always turn Strict, Explicit and probably Infer On. Turn Compare to Binary although you can probably just ignore that and use the default. These are all set with Option statements at the top on. Actually, this is too strong. You may want to turn Explicit off to do late binding. As mentioned in #31 below, this is per partial class file so you can provide late binding to a fragment of your class.

7) Retrain the baby finger and ask on Connect for the IDE to remove EOL semi-colons

8) Get to know events. They are declarative with the Handles clause. Figure out that the Handles clause requires WithEvents on the variable. The common syntax for declaring events does not require the Delegate keyword:

Event MyEvent(ByVal sender As Object, ByVal args As EventArgs)

9) Learn how to use Snippets and download the Snippet Editor. Pay attention to abbreviations. Create the snippets you need. Learn to use the ?<tab> keystrokes to find templates.

VB provides a large number of snippets. It can be tedious to find the ones you use often via the menu, and unlike C# snippets don’t show up in Intellisense. Instead, use the snippet auto-complete which you access by typing the first few characters hitting ? and <tab>. This provides access to the appropriate location in an alphabetized list of snippets. In this case, Enter, as well as Ctl-Enter and whitespace punctuation will select the snippet. For a Select Case with an enum, the snippet does not fill in the values. Also, VB’s snippet expansion doesn’t access the class name, so you’ll have an extra field in dependency property snippets.

10) Take advantage of partial namespaces and aliased namespaces. Do not import classes without a good reason

11) A VB module is roughly a C# static class, except it can be used without naming the class. There is some disagreement over whether this is good. Decide and make a standard, but understand how VB uses modules

12) Spend an hour playing with nullables. VB’s comparisons approximate SQL Servers. C#’s comparisons follow different rules. This will especially bite you if you then cast to a Boolean calling null to go to False

13) VB LINQ doesn’t make you include Select. Don’t use it unless you need it. These statements are equivalent because selecting the iterator variable is inferred:

Dim kd = From s In list2
Dim kd2 = From s In list2 Select s

If you wish to select something other than the iterator variable, you can, of course, use the Select statement to define it.

14) VB LINQ has significantly more keywords making single expression LINQ statements possible and are particularly useful with aggregates, Take and Skip

15) Anonymous type mutability is flexible, while anonymous types in C# are always immutable. Explore the Key keyword, and experience creating anonymous types via LINQ and without LINQ

16) Inferred typing is as easy as in C#

17) Spend some time in casting. TryCast is pretty much the same as “as” in C#, DirectCast performs a cast only, no conversions, even widening integers, allowed. CType does a conversion or a cast. For intrinsic types, it converts. For non-intrinsic types without an overloaded CType operator, it casts and is the same as Direct Cast. If there is an overloaded CType operator that the VB compiler can resolve, CType will use that operator. C# does not have a parallel to CType, nor really one for DirectCast, since widening conversions are performed in strict cases. The parentheses cast performs some conversions, such widening integer conversions and floating point to integers, but does not perform the string to date and string to numeric conversions of VB’s CType operator. VB’s CType operator uses banker’s rounding, while the C# parentheses conversion uses simple rounding (1.5 is rounded down in C#, up in VB and in Convert.Int32, Math.Round, etc).

Initially this might be confusing, but the bottom line is you have the option of just using CType for most casting and conversions without really thinking about it, or to use DirectCast and explicit conversion operators if you want to be more explicit. The choice is yours.

To be honest, I didn’t understand all the intracacies and opinions and have updated this in every version of this post so far. I decided casting and conversions deserved their own discussion (here).

18) Understand the difference between VB operators and methods. Explore the operators, particularly the extra work done by the CType casting operator. This work is generally good for your project and it isn’t a meaningful perf hit

19) Explore all the methods and properties of the Microsoft.VisualBasic and make a team decision whether to use them. You do not have to use anything in this namespace and it is not required in all new framework implementations, although Microsoft will continue to include them. Your team might want to keep these familiar features.

20) If you use the Microsoft.VisualBasic namespace, do some perf tests on the Microsoft.VIsualBasic.Collection and consider outlawing it

21) VB uses parens for both method calls and indexes. Sorry.

22) VB uses a single equals for both comparison and assignment. It works because we can’t assign in line. Not assigning in line is good as it enforces a common best practice.

23) There’s a reason for VB’s oddly named AndAlso and your team will appreciate it. A VB 6 comparison is a binary comparison and not short-circuited. Short circuits are two lines and explicit in VB6. For consistency, And in VB.NET is binary. AndAlso is the logical comparison and is short circuited. This is consistent with C#’s & being shorter than &&. Or/OrElse parallels this.

24) Similar, for consistency with VB6, CInt (and CLng, but not CByte) in VB returns -1. This is the only case in which False equals -1. This may be important if people are doing line by line conversions because you cannot tell in VB6 whether the intent of a comparison was logical or binary.

25) Loops and conditionals do not have parentheses

26) With Option Infer On, iterator types are automatically inferred. C# requires the var keyword:

var list2 = new List<string>() { “Bill”, “Percy”, “Fred”,”George”, “Ron” };
foreach (var k in list2)
{
   // do something
}

While VB infers the type more quietly:

Dim list2 = New List(Of String)(New String() {“Fred”, “George”, “Bill”, “Percy”, “Ron”})
For Each k0 In list2
    ‘ do something
Next

27) Do loops have direct syntax for looping while and until. You can also exit from within a loop. From Help, the syntax for a Do loop is:

Do { While | Until } condition
    [ statements ]
    [ Exit Do ]
    [ statements ]
Loop

-or-

Do
    [ statements ]
    [ Exit Do ]
    [ statements ]
Loop { While | Until } condition

This does not discuss using Continue with loops. In most cases, Continue does the same thing as C# – going to the top of the next iteration and skipping any remaining statements. However, the VB Continue specifies the type of loop so if you have a single Do and For loops nested you can proceed to the next iteration of the outer loop. This is not common. Again from Help:

Continue { Do | For | While }

VB allows a simple Do Loop if you need an infinite loop (such as a wait cycle):

Do
    [ statements ]
    [ Exit Do ]
    [ statements ]
Loop

28) Check the syntax for extension methods. It follows VB’s tradition of being more explicit which will help your team make the transition. In this case, more explicit means the extension method is defined by an attribute. 

29) Get to know the With keyword. You may decide not to use it, but you should understand how to. It can significantly simplify code and because it avoids re-qualification it will also speeds up your application somewhat.

30) Get to know the ByRef/ByVal semantics. You do not specify ref on the call, only the parameter declaration

31) Get to know partial classes. You specify partial on only one class. Options are per partial, not per class, meaning you can have late binding in small portion of your class without binding overall

32) Visual Basic requires a line continuation character – the underscore. While you are typing code, you may get in the habit of including this, and certainly the compiler will catch your mistakes. However, this can be a pain when rewrapping long lines of code. Consider writing a macro to help you wrap code if this annoys you.

33) VB provides module level imports – that means you can use the same set of imports throughout your project, then add more in specific places. The default includes some I’d suggest removing, especially System.Collection (use only System.Collection.Generics

34) VB has extremely powerful features in My. Explore these and how the Intellisense experience can lead coders to do the right thing. Consider adding your own My features.

35) For WinForms code, VB has a very nice startup framework that includes things like unhandled exception that you may be doing in your C# startup routines. The VB mechanism is very strong and you probably want to use it. You can access these event from the Project Dialog

36) The targeted framework is under advanced options in the Compile tab of Project dialog

37) Namespaces work differently if no namespace is defined. In C# the class goes into the default namespace. In VB, the class goes into the project level namespace. If you put any namespace as the class level, its appended to the project namespace. Assuming all classes in the project are in the same namespace this is very good and flexible. However, if even one class needs to go into another namespace, you have to shift strategy and add explicit namespaces to every file.

38) Interfaces work differently. They are always explicit in VB and you can specify scope within the same declaration for the method addressed directly through the instance. You will probably get to like this very much as it makes the intent much more clear.

39) Hitting Enter on an Interface or Inherits statement creates or updates the required properties and methods. They are empty when created (no “Throw NotImplemented…”). They are not placed in their own region.

40) Refactoring in the box is limited to Symbolic Rename which works well, although simplified. No preview – but who actually previews? If you want additional refactorings, download Refactor! which is free for Visual Basic users.I understand Refactor Pro removes those pesky semi-colons you accidentally typed

41) VB has a handy “Go To Type Definition” in the right click menu. It does not have “Surround With”

42) No iterators. If you need them, consider defining the class in C#

43) While you rarely need to explore it, creating explicit event management code is available and very slick. Thanks Rocky for demanding this.

44) VB XLINQ is amazing. Learn how to use XML namespaces for Intellisense, manage XML as XML regarding missing values (this took a 40 line piece of C# code to three lines in VB, how to output XML, and how to use it as a generalized text processing tool

45) When using VB’s XLINQ for text processing, use lots of calls to embedded expressions rather than creating a monolithic statement as XML literals are still debugged on a per/statement level

46) Creating optional parameters in your new classes is probably not a good idea because it isn’t compliant with C#. Use overloads as you would in C#. However, if you are interacting with code that has optional parameters, you can ignore that Missing constant entirely. Adds a lot of clarity.

47) Consider using named arguments, particularly in dealing with Office. You need to learn this syntax anyway for attributes

48) When you declare array bounds you declare the upper limit, not the length. Thus a string of four elements is Dim x(3) As String. Note that you can include the array bound in the declaration. You can put the parentheses on either the variable name or type, but you must put them on the variable name if you are specifying the upper bound.

49) No multi-line lambdas in this version. When you need a closure, you must use a class. If you do not know how to use a class to build a closure, well, ask me and that probably deserves a blog post. VB also does not have true anonymous methods or void lambdas.

50) Read my column and Bill McCarthy’s column (I assume you were already reading Bill Wagner’s). That’s not flippant, we’re covering a lot of basics and overlooked issues, primarily the basics and details of new features

51) Yes, VB does have operator overloading

52) You do not have to repeat the declaration for new variables. Use the second syntax instead of the first:

Dim c As Customer = NewCustomer(<params>)
Dim c As New Customer(<params>)

53) Nothing is not quite the same as null. Nothing is closer to C#’s use of default. If you have a reference type, default in C# is null. Thus, Nothing is the same as null when assigned to or compared with a reference type.

54) The GetType operator in VB is roughly the same as typeof operator in C#. The TypeOf <variable> Is <typeName> is roughly the same as the is operator in C#. Is (without TypeOf) in VB is roughly the same as a == with reference types in C#. The caveat is that this forces the reference type semantics regardless of operator overloads.

55) You can include array bounds

56) Visual Basic has a Redim and Redim Preserve to re-dimension arrays. These can save you some code and possibilities for error, particularly when you use Redim Preserve to keep the currents content of your array.

57) Only use Dim within a class (where you must use it). Use scope declarations in other locations such as class level variables.

58) Visual Basic has separate operators for integer and floating point division. Integer division is \ while floating point is the traditional /. You will hurt performance if you do floating point division only to round back to an integer.

59) Visual Basic has two operators for concatenating strings. You can use either & or +, which accomplish slightly different things. & converts both operands to string via the class’s ToString method. It will not fail with null values, and will concatenate numerics, etc. The + operator must perform type checking before the concatenation and is therefore slower than the & according to MSDN

60) Do not use On Error. This is a holdover from VB6. While you can accomplish VB6-like behavior it makes for very messy and potentially slower IL, regardless of whether an exception occurs. On the other hand, if you’re desperately trying to move code into .NET, perhaps it will be a short term crutch.

61) While it may not aid readability, if you feel compelled to include multiple statements on one line, use a colon to separate them.

62) You can’t do in line assignments – a single equals is a comparison operator in these contexts. Similarly, you can’t increment and decrement in place. You can however use the increment and assign (+=), concatenate and assign (&=) and similar operators.

63) The Default keyword defines the property that is analogous to the indexer in C#. This property must have a parameter and can be accessed without specifying the property name. The following two code fragments (where list is System.Collections.Generic.List(Of T)) are identical:

X = list(42)
X = list.Item(42)

You can define default properties on your own collection classes via the Default keyword.

64) The meaning of “anonymous delegate” is different in Visual Basic and C#. In C# it’s an inline delegate. In VB it’s basically an inferred delegate (thanks to Lucian for the fragment):

Delegate Function D(ByVal x As Integer) As Integer
Dim f = Function(x As Integer) x + 1
Dim d1 As D = f   
Dim d2 As Func(Of Integer, Integer) = f 

65) Constraint syntax on generics is a little different, along with providing multiple constraints. The VB and C# syntax below are identical:

Public Class SomeClass( _
     Of T As New, _
          V As IComparable)

public class SomeClass<T, V>
         where T : new()
         where V : IComparable

and with multiple constraints:

Public Class SomeClass( _
           Of T As {BizObject, New}, _
               V As IComparable)

public class SomeClass<T, V>
       where T : BizObject, new()
       where V : IComparable

66) Starting in Visual Basic 9.0, VB does have ternary and default assignment operators. Ternary operators take three operands. The first must evaluate to a Boolean, and if true, the second value is returned. Otherwise the third value is returned. These are effectively equivalent:

If(boolValue, first, second) ‘ VB

boolValue ? first : second // C#

It’s important to note that this differs from the older IIf function. The IIf function evaluated all argument expressions regardless of the value of the Boolean. This often defeats the purpose of the ternary operator because one of the operands is invalid based on the Boolean value:

y = If(x Is Nothing, defaultValue, x.SomePropertyName)

A default assignment operator takes two values. If the first value is not null, it is used. If the first value is null, the second argument is used. Again, this is an operator, not a method, so the second expression is not evaluated unless it is needed:

x = If(nullableInt, -1) ‘ VB

x = nullableInt ?? -1 // C#

67) VB does not have a collection initializer. You can, however, use the overload of List that takes an IList as input and still make the assignment on one line:

Dim list2 = New List(Of String)(New String() {“Fred”, “George”, “Bill”, “Percy”, “Ron”})

68) (replaced as the previous 68 fit better into #9 and I’m not going for a record here)
When passing an out or ref argument to a function, there is no call site (as in the where you make the call) indicator for the out or ref status. The indicator is only on the declaration.

—————————————————————————————————————-

So, now it’s your turn. What do you think C# coders overlook when they write code in VB? Include any stupid mistakes you’ve seen in automatic translators in the help.

I’m not trying to restart any language wars, so don’t bother going there. I just wanted to ensure there was a resource for C# coders that needed to write VB code.

Oh, and if you’re looking for a job in the Springs, I’ll hook you up with the recruiter, especially if you’re a VB.NET coder that already knew everything in this list.

Thanks to Bill McCarthy for suggesting some corrections to 17, 18 and 24 as well as pointing out something in one of his articles that led to 51.

I’ve updated this on 7/22/08 and plan to continue to update this list as people point out additional things, or I think of them. Thanks to a ton of people for their comments, including Jim Wooley, Jay B. Harlow, Lucian Wischik, Erik Meijer, Rod Stephens, Bill McCarthy, Herfried K. Wagner, Cor Ligthert, Rob Teixeira, Rocky Lhotka, Jeff Certain, Steve Smith and “NotMyself”. Also, Eric and Int19H for pointing out politely a dumb error I made yesterday in the code for 26.

24 thoughts on “What a C# Coder Should Know Before They Write VB”

  1. I spend a lot of time in C# and VB, This is a nice resource to remind me what keyword I am looking for in VB. If its possible could you link to mdsn some of the keywords(continue, with, loop, exit…) are difficult to search for on that site. Just lazy I know. That’s also why I use CodeRush I spend very little time having to think about language specific syntax.

  2. This post came at a great time for me… I did a lot of VB5/6 then moved to VB.NET. However, I’ve been doing C# for the last 2 years. I just started a project using VB, so this is a great refresher.

  3. Kathleen,

    This was a great post. And, it gives me an idea: Do you think Patrick Meader would go for a couple articles where you and I wrote the same algorithms idiomatically in C# & VB.NET? We could explain the differences, and why each language took that path.

    Let me know what you think: bill.wagner@srtsolutions.com

  4. Kat,

    The biggest thing I had to get used to in switching from C# to VB was trinary operator…

    IIf Is Not ?:

    In C# ?: is a simple way to write if/else statements.

    In VB.NET IIF actually executes both blocks of code and returns what ever the correct one is.. this caused me no end of problems until I looked it up.

  5. Hi Kathleen, very nice list. There were a few points where an example would clarify things, I think. For instance, #5… what would this do for me?
    #26 Can you show an example where this would matter?
    #13 would benefit from an example showing two statements with/without select and how they’re equivalent, I think.
    #27 again a quick example (a link to one would do here) would be handy for some, I think.

  6. NotMyself,

    (Sorry I don’t have a better name for you)

    Thanks for bringing this up. It was definitely in my brain at one point, but it fell out prior to making the page.

    You are incorrect about the lack of ternary operator. In VB 9 (.NET 3.5) VB got a true ternary operator which is the operator version of If. I’ll add an example, but

    x = If(whatever, isTrueValue, isFalseValue)

    this is a true ternary – the boolean condition (whatever) and the return value (isTrueValue OR isFalseValue) is evaluated. The other value is NOT evaluated. This is not a method call, but a true ternary.

    VB also got

    x = If(whatever, defaultValue)

    in this case, if whatever is not null/Nothing it is returned. Otherwise the defaultValue is used.

    You are correct that IIf is fatally flawed and should not be used – espicially in VB 9 and beyond.

    Thanks for the comment and I’ll include that in the next rev of the post.

    Kathleen

  7. Steve,

    You’re right. I actually started this list thinking I’d take an hour and jot down a few things and it grew!

    I’ll look at adding clarity to the list, particularly the parts you point out.

    Kathleen

  8. #26 is actually incorrect – you absolutely can infer type of variable in foreach loop in C#, you just need to tell it to do so explicitly using “var”:

    var list2 = new List() { “Bill”, “Percy”, “Fred”,”George”, “Ron” };
    foreach (var k in list2)
    {
    // do something
    }

    #27 misses the fact that neither pre- nor the postcondition is required on a Do-Loop statement (but then MSDN misses it too). This means that VB actually has a dedicated construct for “endless loops”, similar to C# “for(;;)”. Actually, Do-Loop is probably the best VB statement, considering how neatly it covers all possible options with syntax that makes the exact behavior of the loop very clear.

    Then again, the lack of iterators and overly verbose lambdas are the dealbreakers for me. Iterators especially are a necessity in the LINQ age. So I’ll stick with C# for now… but I sure hope we get those XML literals, too.

  9. Kathleen,

    Nice list… Appreciate your effort. There is a slight mistake in #26, the correct C# code is:

    var list2 = new List() { “Bill”, “Percy” };
    foreach (var k in list2) {
    // do something
    }

    “k” must be declared, either explicitly or via type inference. In this clip k is correctly inferred to be of type string.

    -e

  10. One more to consider:
    VB doesn’t require (or permit, as far as I know) the callsite declarations required by C# for ref/out parameters. This also effectively eliminates the distinction between ref and out parameters because the stronger definite assignment rules for out parameters aren’t checked.

  11. Int19H,

    What do you mean by “overly verbose”? You mean you hate the “Function” keword? Or do you mean the backflips you need to do to accoplish a proper closure in a multi-line lambda.

    Iterators are a problem and I think the lack of multi-line lambdas are a real issue.

    To be clear, the purpose of this post is not to convert anyone – those battles aren’t meaningful. The goal is to provide some detailed information to help anyoen crossing over.

    As for XML literals, this seems like such a non-issue. If you are doing XLinq, XML literals or text processing – isn’t it to a specific schema. If so, do you really want it in your main body of code? If its in a separate wrapper assembly anyway (where I think it belongs) who cares what the base language in that assembly is? Wrappers are simple and using VB ensures they are isolated.

    Thanks to you and everyone else that commented on this version. I am updating it per these comments.

  12. Hi Kathleen,

    Very well coverage.
    You might add the following, if not added already.

    use of paramArray (VB), params (c#) for variable number of arguments.

    Exit Sub/Function (VB), return/return X (c#)
    Exit Do/For (VB), break; (C#)

    Me (VB), this (c#)

    len(myString) (VB) and myString.Length (c#)
    and other string related functions such as Mid, Substring, Right, Left

  13. Those string functions are there just for retrocompatibility… and I wouldn’t use them. The proper way of doing this would be using the native .NET methods. The same goes for the exit keywords… better to use the return statement…

    Some things that maybe should be mentioned as well are: VB supports optional parameters, although a lot of people consider overloading the right way, VB doesn’t have unsafe blocks, stackalloc, etc. Also, I think VB uses a different model thread appartment, but not sure on this one, and maybe the My spacename could be named as well, although a lot of people is against it. There are also the application events at design time, saving settings on exit, chosing if the application is single instance…

  14. > What do you mean by “overly verbose”? You mean you hate the “Function” keword?

    Well, yes. I think that part of the reason for lambdas is that they should be short and concise – something that I feel the VB syntax is lacking at the moment. The one the C# guys came up with is pure genius (and reminds me fondly of Haskell, where it is obviously shamelessly borrowed from ;).

    > As for XML literals, this seems like such a non-issue. If you are doing XLinq, XML literals or text processing – isn’t it to a specific schema. If so, do you really want it in your main body of code?

    I have the misfortune to code for SharePoint, and so my code is often littered with parametrized CAML query fragments. Building them by directly by invoking XElement constructors is too verbose for my liking, and using literal strings with formatting placeholders is brittle because of the need to escape everything properly. Proper XML literals would really help there.

    And yes, it is part of the business logic processing, so refactoring a specific query to a separate assembly doesn’t sound like a good idea to me.

  15. > VB doesn’t require (or permit, as far as I know) the callsite declarations required by C# for ref/out parameters. This also effectively eliminates the distinction between ref and out parameters because the stronger definite assignment rules for out parameters aren’t checked.

    Since VB always initializes locals to their default values, it doesn’t bother with definite assignment rules at all. And of course you can apply InAttribute and OutAttribute directly for other cases where they matter.

  16. Int 19H,

    So, you have to couple your business logic to Sharepoint? I feel for you having to use Sharepoint at all.

    Kathleen

  17. Hi Kathleen,

    I love VB and I hate C# ;))

    I try to convert in vb the following and I have a problem with the anonymous method :

    this.RegisterShortcut(NEW_Shortcut,
    delegate()
    {
    this.SendEventToDataInterfaceInteraction((int)DataInterfaceInteraction.EventID.New);
    });

    With :

    private const Keys NEW_Shortcut = Keys.Control | Keys.N;

    ///

    /// Registers a shortcut and it’s related action with this handler.
    ///

    /// The shortcut.
    /// The shortcut action.
    private void RegisterShortcut(Keys shortcut, ExecuteShortcut shortcutAction)
    {
    if (!m_Shortcuts.ContainsKey(shortcut))
    {
    m_Shortcuts.Add(shortcut, shortcutAction);
    }
    }

    private void SendEventToDataInterfaceInteraction(int eventId, params object[] args)
    {
    m_Interactions.Send(eventId);
    m_Interactions.Execute();
    }

    I can translate that in VB :

    Private Const NEW_Shortcut As Keys = Keys.Control Or Keys.N

    ”’

    ”’ Registers a shortcut and it’s related action with this handler.
    ”’

    ”’ The shortcut.
    ”’ The shortcut action.
    Private Sub RegisterShortcut(shortcut As Keys, shortcutAction As ExecuteShortcut)
    If Not m_Shortcuts.ContainsKey(shortcut) Then
    m_Shortcuts.Add(shortcut, shortcutAction)
    End If
    End Sub

    Private Sub SendEventToDataInterfaceInteraction(ByVal eventId As Integer, _
    ByVal ParamArray args As Object())
    m_Interactions.Send(eventId)
    m_Interactions.Execute()
    End Sub

    Thanks for your help to translate the anonymous method with the delegate. I can’t to do that, there is no event ..

    I hope it will be useful for others coders.

  18. I think I found the solution (with help of a sample) :

    Me.RegisterShortcut(NEW_Shortcut, AddressOf ConvertedAnonymousMethod)

    Private Sub ConvertedAnonymousMethod()
    Me.SendEventToDataInterfaceInteraction(CInt(DataInterfaceInteraction.EventID.[New]))
    End Sub

  19. Richard III only has one matinee on Sunday, July 17th. The Directors muluatly decided that they would rather have more nighttime performances of Richard and more daytime performances of As You Like It.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>