By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,988 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,988 IT Pros & Developers. It's quick & easy.

Saving data to a sequential access file

P: 24
Hi, I'm trying to create a program where the user can enter check information and the information is saved to 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 the ***** in front of below. Can anyone help me figure out how to fix this error? Thanks for your help. Here's my code:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit On
  2. Option Strict On
  3. Public Class Form1
  5.     Public Class payment
  6.         Public checknumber As String
  7.         Public checkdate As Date
  8.         Public payee As String
  9.         Public checkamount As Decimal
  10.     End Class
  12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  13.         Me.Close()
  14.     End Sub
  18.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  19.         Dim path As String = "C:\documents and settings\tammy and rich\my documents\visual studio 2005\projects\franklin calendars"
  20.         Dim ourcheck As New payment
  21.         Dim newlineindex As Integer
  22.         Dim recordindex As Integer
  23.         If checknumbertextbox.Text <> String.Empty AndAlso checkdatetextbox.Text <> String.Empty AndAlso payeetextbox.Text <> String.Empty AndAlso checkamounttextbox.Text <> String.Empty Then
  24.             ourcheck.checknumber = checknumbertextbox.Text
  25.             newlineindex = Text.IndexOf(ControlChars.NewLine, recordIndex)
  26.     *******   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)
  27.             checknumbertextbox.Text = String.Empty
  28.             checkdatetextbox.Text = String.Empty
  29.             payeetextbox.Text = String.Empty
  30.             checkamounttextbox.Text = String.Empty
  31.         End If
  32.         checknumbertextbox.Focus()
Dec 1 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.