views:

215

answers:

1

I get this error when attempting to debug my form, I cannot see where at all the error could be (also does not highlight where), anyone have any suggestions?

An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.

Dim dateCrap As String = "Date:"
Dim IPcrap As String = "Ip:"
Dim pcCrap As String = "Computer:"
Dim programCrap As String = "Program:"

Dim textz As String
Dim sep() As String = {vbNewLine & vbNewLine}
Dim sections() As String = Text.Split(sep, StringSplitOptions.None)

Dim NewArray() As String = TextBox1.Text.Split(vbNewLine)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    textz = TextBox1.Text
End Sub
+1  A: 

The error is here:

Dim textz As String = TextBox1.Text

and here:

Dim NewArray() As String = TextBox1.Text.Split(vbNewLine)

and possibly here:

Dim sections() As String = Text.Split(sep, StringSplitOptions.None)

You cannot initialize a member like this because this code is basically executed in the constructor, before TextBox1 (or any other control/property) is initialized, hence it is Nothing.

Put all initializations that refer to controls inside the Form_Load event – that’s what it’s there for.

Konrad Rudolph
Same outcome, can't seem to find anything else considering what you suggested.
Ben
@Ben: If the outcome is the same, then you’ve overlooked a similar initialization. Remove all other code form your form to reduce the problem.
Konrad Rudolph
Why did this get downvoted?
Konrad Rudolph