My project is to create a program where the user can enter check information and the program saves it in a sequential access file. I'm getting an error when I run the program. The error is "Object reference not set to an instance of an object." and I'm getting it on the line that I have *** in front of below, towards the bottom of the code. Can anyone offer suggestions to how I might fix this error? Thanks for your help.
CODE
Option Explicit On
Option Strict On
Public Class Form1
Public Class payment
Public checknumber As String
Public checkdate As Date
Public payee As String
Public checkamount As Decimal
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim path As String = "C:\documents and settings\tammy and rich\my documents\visual studio 2005\projects\franklin calendars"
Dim ourcheck As New payment
Dim newlineindex As Integer
Dim recordindex As Integer
If checknumbertextbox.Text <> String.Empty AndAlso checkdatetextbox.Text <> String.Empty AndAlso payeetextbox.Text <> String.Empty AndAlso checkamounttextbox.Text <> String.Empty Then
ourcheck.checknumber = checknumbertextbox.Text
newlineindex = Text.IndexOf(ControlChars.NewLine, recordIndex)
***** My.Computer.FileSystem.WriteAllText(path & "checkfile.txt", ourcheck.checknumber.PadRight(20) & ourcheck.checkdate.ToString.PadLeft(10) & ourcheck.payee.ToString.PadLeft(10) & ourcheck.checkamount.ToString("N2").PadLeft(10) & ControlChars.NewLine, True)
checknumbertextbox.Text = String.Empty
checkdatetextbox.Text = String.Empty
payeetextbox.Text = String.Empty
checkamounttextbox.Text = String.Empty
End If
checknumbertextbox.Focus()
End Sub
End Class