VB Migration Partner

KNOWLEDGE BASE - Forms and controls

Previous | Index | Next 

[PRB] SelFontName, SelFontSize, SelBold, SelItalic, SelUnderline, and SelStrikeThru properties of RichTextBox control return Nothing instead of Null

Under VB6, the SelFontName, SelFontSize, SelBold, SelItalic, SelUnderline, and SelStrikeThru properties of the RichTextBox control return Null if the selection contains characters with different attributes. For example, if the selection contains both regular characters and characters in boldface then the SelBold property returns Null.

Many word processor-like VB6 applications display a toolbar that allows users to change the attributes of the text that is currently selected in a RichTextBox control. The code that executes when a button on the toolbar is clicked is similar to the following one:

        Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
            Select Case Button.Key
                Case "Bold"
                    RichTextBox1.SelBold = Not RichTextBox1.SelBold
                Case "Italic"
                    RichTextBox1.SelItalic = Not RichTextBox1.SelItalic
                Case "Underline"
                    RichTextBox1.SelUnderline = Not RichTextBox1.SelUnderline
                ' more commands here ...
            End Select
        End Sub

Even if it isn’t immediately apparent, this code relies on the fact that the SelBold, SelItalic, and SelUnderline properties return Null if the selected characters have mixed attributes. In fact, if the SelBold property returns Null, then the Not operator converts such Null value to True, therefore characters in the selection get the boldface style.

The VB6RichTextBox control exposes all the SelXxxx properties that the original VB6 control exposes; if characters with mixed attributes are currently selected these properties return either False or Nothing. More precisely, they return False if all the characters in the selection use same font but possibly different attributes; they return Nothing if the selection includes characters rendered with a different font.

This behavior difference rarely affects converted applications. For example, the previous code continues to work correctly regardless of whether the SelBold, SelItalic, and SelUnderline properties return False or Nothing. In either case, the new value of the property will be True, exactly as it happens in the original VB6 code.

In some cases, however, this detail can be important, for example when the original VB6 code explicitly tests the value of these properties with the IsNull function. Keep it in mind when you see that a RichTextBox in the converted application doesn’t work as expected.

Previous | Index | Next 

Follow Francesco Balena on VB6 migration’s group on


Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.

Code Architects and its partners offers remote and onsite migration services.

More details

Subscribe to our free newsletter for useful VB6 migration tips and techniques.


To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice

A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial

The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote

Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers