Results 1 to 5 of 5

Thread: Object reference not set to an instance of an object

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Posts
    114

    Object reference not set to an instance of an object

    Am trying to remove this error: Object reference not set to an instance of an object - what causes this error?

    Code:
        ''''' 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:

    Code:
     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:

    Code:
    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 by nqioweryuadfge; Mar 16th, 2017 at 06:38 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width