I am new to VB programming. I recently copied a code from internet, which gives me an error of Object Reference Not Set To Instance Of Object, NULL POINTER EXCEPTION. I couldn't understand where the problem lies..!! Help..
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If My.Settings.Names Is Nothing Then
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Must Fill all Fields")
Else
Dim name As String = TextBox1.Text
Dim number As String = TextBox2.Text
My.Settings.Names.Add(name + " :: " + number)
My.Settings.Save()
Me.Close()
End If
Else
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Must Fill all Fields")
Else
My.Settings.Names.Add(TextBox1.Text + " :: " + TextBox2.Text) /*ERROR COMES HERE*/
My.Settings.Save()
Me.Close()
End If
End If
TextBox1.Clear()
TextBox2.Clear()
Form1.ListBox1.Items.Clear()
For Each Name As String In My.Settings.Names
Form1.ListBox1.Items.Add(Name)
Next
End Sub