Additional information: Object reference not set to an instance ofan object.................

S

Supra

'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.
in module:
Dim nrtb As New RichTextBox
Sub DisplayMessage(ByVal rtb As RichTextBox, ByVal sText As String,
Optional ByVal Colour As String = "")
rtb.SelectionStart = rtb.Text.Length
' rtb.doColor(rtb, DirectCast(sText, String))
' rtb.doColor(rtb, CType(sText, String))
rtb.SelectedText = nrtb.doColor(rtb, sText) <=======error
occurred here
rtb.SelectionStart = rtb.Text.Length
rtb.ScrollToCaret()
sText = String.Empty
End Sub
i don't know if i should do sub new() in module or in usercontrol or both
regards,
 
R

Robby

The problem could be that method doColor is not a member of class RichTextBox. In your code, variable nrtb is an instance of class RichTextBox so the call to method nrtb.doColor(...) is not being resolved since method doColor is not a member of class RichTextBox.

Robby

'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.
in module:
Dim nrtb As New RichTextBox
Sub DisplayMessage(ByVal rtb As RichTextBox, ByVal sText As String, Optional ByVal Colour As String = "")
rtb.SelectionStart = rtb.Text.Length
' rtb.doColor(rtb, DirectCast(sText, String))
' rtb.doColor(rtb, CType(sText, String))
rtb.SelectedText = nrtb.doColor(rtb, sText) <=======error occurred here
rtb.SelectionStart = rtb.Text.Length
rtb.ScrollToCaret()
sText = String.Empty
End Sub
i don't know if i should do sub new() in module or in usercontrol or both
regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top