Just spent way too much time fixing VB code coloring on MSDN2

You may have already noticed this, but the current build of MSDN2 has a bug in the way it colors VB code snippets, as you can see here (scroll down, there are quite a few problems in the code snippet coloring, see how many you can spot!)… turns out the code wasn’t handling comments right, text in quotes, and it didn’t have a full list of the VB keywords (so MsgBox was not recognized, for example). I’ve fixed it all up now (I think) so that code will work its way through review and test then get added to some not-too-distant update of the site code… but for now, here is the revised output for those particular code samples.

Broken

' Imports statements must be at the top of a module.
Imports Microsoft.VisualBasic.CallType
Sub TestCallByName1()
    'Set a property.
    CallByName(TextBox1, "Text", CallType.Set, "New Text")

    'Retrieve the value of a property.
    MsgBox(CallByName(TextBox1, "Text", CallType.Get))

    'Call a method.
    CallByName(TextBox1, "Hide", CallType.Method)
End Sub
Public Sub TestCallByName2()
    Dim col As New Collection()

    'Store the string "Item One" in a collection by 
    'calling the Add method.
    CallByName(col, "Add", CallType.Method, "Item One")

    'Retrieve the first entry from the collection using the 
    'Item property and display it using MsgBox().
    MsgBox(CallByName(col, "Item", CallType.Get, 1))
End Sub

Fixed

' Imports statements must be at the top of a module.
Imports Microsoft.VisualBasic.CallType
Sub TestCallByName1()
    'Set a property.
    CallByName(TextBox1, "Text", CallType.Set, "New Text")

    'Retrieve the value of a property.
    MsgBox(CallByName(TextBox1, "Text", CallType.Get))

    'Call a method.
    CallByName(TextBox1, "Hide", CallType.Method)
End Sub
Public Sub TestCallByName2()
    Dim col As New Collection()

    'Store the string "Item One" in a collection by 
    'calling the Add method.
    CallByName(col, "Add", CallType.Method, "Item One")

    'Retrieve the first entry from the collection using the 
    'Item property and display it using MsgBox().
    MsgBox(CallByName(col, "Item", CallType.Get, 1))
End Sub
Just spent way too much time fixing VB code coloring on MSDN2

2 Responses

  1. Hey Duncan,

    MsgBox and CallByBName aren’t keywords AFAIK. Here, they aren’t coloured in the IDE.

    BTW: I have code colouring code for the VB snipept Editor which you are welcome to borrow. It will need tweaking to deal with escaped html though.

    Bill McCarthy November 17, 2005 at 12:08 pm #
  2. I think you have a point there Bill, I believe I added in too many lists… MsgBox and CallByName are built-in Functions, but not keywords…

    Duncan Mackenzie November 17, 2005 at 10:48 pm #

Leave a Reply