Question Object reference not set to an instance of an object

KelvinN.

New member
Joined
Nov 28, 2015
Messages
4
Location
Nairobi
Programming Experience
Beginner
Am trying to remove this error: Object reference not set to an instance of an object - what causes this error?

VB.NET:
    ''''' Remove words in Angle Brackets

        Private Function GetWordWithOutBracketedText(SelectedReplacement As String) As String
            ' check if the selected replacement contains bracket "("
            If Strings.InStr(SelectedReplacement, " (") = 0 Then
                Return SelectedReplacement ' if not exists return the same string back
            End If

            ' if bracket is there in string split it with bracket
            Dim arr() As String = Strings.Split(SelectedReplacement, " (")

            ' send back the first element from splitted array as only first part is the replacement text
            Return arr(0)

        End Function
When the contextMenuStrip appears, and I put this code on it here it never works:

VB.NET:
 Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening

RichTextBox1.SelectedText = GetWordWithOutBracketedText(kamau)

End Sub

I get this error:

VB.NET:
An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll

    Additional information: Object reference not set to an instance of an object.
 
Last edited:

Latest posts

Back
Top