Skip to main content
All docs
V22.2
  • Visual Basic Embeddings

    • 5 minutes to read

    This topic lists available Selection Embeddings for Visual Basic.

    Try..Catch..Finally

    If..End If

    SyncLock

    Namespace[1]

    Try..Finally

    If..Else End If

    TryCast(..)

    Stopwatch[1]

    Try..Catch

    While..End While

    Embeddings for Rich Comments

    To string[1]

    #Region..#End Region

    Do..While

    BeginUpdate..EndUpdate[1]

    Comment box[1]

    #If..#End If

    Using..End Using

    WaitCursor[1]


    Try..Catch..Finally

    Embeds the selected text (code, comments) into the Try..Catch..Finally code block. This embedding also places the caret in the Catch section and drops a marker in the Finally section.

    Try
        ' Embedded text
    Catch ex As Exception
        
    Finally
        '
    End Try
    

    You can also use the T shortcut for this embedding.[2]


    Try..Finally

    Embeds the selected text (code, comments) into the Try..Finally code block and places the caret in the Finally section.

    Try
        ' Embedded text
    Finally
        
    End Try
    

    You can also use the F shortcut for this embedding.[2]


    Try..Catch

    Embeds the selected text (code, comments) into the Try..Catch code block and places the caret in the Catch section.

    Try
        ' Embedded text
    Catch ex As Exception
        
    End Try
    

    You can also use the C shortcut for this embedding.[2]


    #Region..#End Region

    Embeds the selected text (code, comments) between the #Region and #End Region directives.

    #Region ""
            ' Embedded text
    #End Region
    

    You can also use the Ctrl + 3 shortcut for this embedding.


    #If..#End If

    Embeds the selected text (code, comments) between the #If and #End If directives and places the caret after the #If directive.

    #If Then
            ' Embedded text
    #End If
    

    If.. End If

    Embeds the selected text (code, comments) into the If.. End If conditional block and places the caret in the If section.

    If Then
        'Embedded text
    End If
    

    If..Else End If

    Embeds the selected text (code, comments) into the If..End If conditional block with the Else branch. This embedding also selects the conditional expression placeholder and places the caret before this placeholder.

    If Expression Then
        ' Embedded text
    Else
    
    End If
    

    While..End While

    Embeds the selected text (code, comments) into the While..End While loop and places the caret after While.

    While 
    ' Embedded text
    End While
    

    Do..While

    Embeds the selected text (code, comments) into the Do..While loop and places the caret after While.

    Do
        ' Embedded text
    Loop While 
    


    Using.. End Using

    Embeds the selected text (code, comments) into the Using..End Using block and places the caret after Using.

    Using 
      ' Embedded text
    End Using
    

    SyncLock

    Embeds the selected text (code, comments) into the Lock..SyncLock block and places the caret after SyncLock.

    SyncLock 
        ' Embedded text
    End SyncLock
    

    TryCast(..)

    Embeds the selected text (code, comments) into the TryCast(..) code block.

    TryCast('Embedded text, Type)
    

    Embeddings for Rich Comments

    CodeRush includes embeddings that allow you to format selected text within comments. The following embeddings are available:

    To use these embedding, enable the Rich Comments feature.

    Bold

    Formats the selected text within a comment as bold.

    ' **Bold** text
    

    You can also use the Ctrl + B shortcut for this embedding.

    Italic

    Formats the selected text within a comment as italic.

    ' *Italic* text
    

    You can also use the Ctrl + I shortcut for this embedding.

    Underline

    Formats the selected text within a comment as underline.

    ' _Underline_ text
    

    You can also use the Ctrl + U shortcut for this embedding.

    Strikethrough

    Formats the selected text within a comment as underline.

    ' ~Strikethrough~ text
    

    You can also use the Ctrl + S shortcut for this embedding. This shortcut is initially disabled. To enable it, refer to the Selection | Embedding group in the shortcuts configuration.

    Hidden Embeddings in the Code Actions Menu

    BeginUpdate..EndUpdate

    Embeds the selected text (code, comments) between the BeginUpdate and EndUpdate method calls of an object from the clipboard.

    This embedding uses the «Paste» Text Command and requires an identifier in the clipboard.

    «Paste».BeginUpdate()
    Try
      ' Embedded text
    Finally
    «Paste».EndUpdate()
    End Try
    

    WaitCursor

    Embeds the selected text (code, comments) into the Try..Finally block. The WaitCursor is used during the selected code lines’ execution.

    This embedding also creates linked identifiers for references to the saveCursor variable. The System.Windows.Forms namespace should be referenced.

    Dim saveCursor As Cursor = Cursor.Current
    Try
        Cursor.Current = Cursors.WaitCursor
        ' Embedded text
    Finally
        Cursor.Current = saveCursor
    End Try
    

    Namespace

    Embeds the selected text (code, comments) into the Namespace..End Namespace code block.

    Namespace MyNamespace
        ' Embedded text
    End Namespace
    

    Stopwatch

    This embedding performs the following actions:

    • Creates a Stopwatch instance of System.Diagnostics.

    • Embeds the selected text (code, comments) into the Try..Finally block

    • Creates linked identifiers for references to the stopwatch variable

    • Starts the stopwatch before the embedded text

    • Stops the stopwatch after the embedded text

    • Outputs the stopwatch.Elapsed value to the console

    Dim stopwatch As New Stopwatch()
    stopwatch.Start()
    Try
        ' Embedded text
    Finally
        stopwatch.Stop()
    End Try
    Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed)
    

    To string

    Quotes the selected code.

    Before Embedding:

    Embedded text.
    

    After Embedding:

    "Embedded text"
    

    Comment box

    Embeds the selected text (code, comments) into the comment box.

    Before Embedding:

    ' Embedded text
    

    After Embedding:

    ' •——————————————————•
    ' | ' Embedded text |
    ' •——————————————————•
    
    Footnotes
    1. The embedding is hidden in the Code Actions menu. Use the “Visible in the Code Actions (light bulb) menu” toolbar button in the Editor | All Languages | Selection Embeddings options page to show it.

    2. This shortcut is initially disabled. For information on how to enable this shortcut, refer to the following topic section: Enable One-Key Selection Embedding Shortcuts

    See Also