Dear all;
Am new to VB.
I wrote a small program to write some info to a file. But when I run it I am getting an error message:
"Additional information: Object reference not set to an instance of an object"
The error is asociated with a writeLine(1,var). It runs ok the first round but fails with that error above another time.
This is the code: The problem is with the WrIteline command
Thank you in advance
Edi
Dim intWeight As Integer
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub frmDataentry_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtDataEnter.Focus()
lblDate.Text = Today
End Sub
Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim CurrentDate As Date
Dim weight As Integer
Dim txtLine As String
Dim txtFileContent As String = ""
'Dim Myline As New String()
txtLine = ""
CurrentDate = lblDate.Text
weight = txtDataEnter.Text
'txtLine += frmInfoTrack.GetFileContent() + ControlChars.CrLf + "#" + CurrentDate + "#" + "," + Str(weight)
txtFileContent = frmInfoTrack.GetFileContent()
'txtLine += txtFileContent + ControlChars.CrLf + "#" + CurrentDate + "#" + "," + Str(weight)
txtLine += txtFileContent + "#" + CurrentDate + "#" + "," + Str(weight)
MessageBox.Show("This is content of file" + frmInfoTrack.GetFileContent())
MessageBox.Show("this is the content of txtline" + txtLine)
FileOpen(1, frmInfoTrack.AppPath + "Note.ini", OpenMode.Output)
'WriteLine(1, CurrentDate, weight)
Writeline(1,txtLine)
FileClose(1)
txtDataEnter.Text = ""
'Debug.WriteLine(frmInfoTrack.GetFileContent())
MessageBox.Show("This is content after writing" + frmInfoTrack.GetFileContent())
txtLine = ""
Exit Sub
End Sub
End Class
Am new to VB.
I wrote a small program to write some info to a file. But when I run it I am getting an error message:
"Additional information: Object reference not set to an instance of an object"
The error is asociated with a writeLine(1,var). It runs ok the first round but fails with that error above another time.
This is the code: The problem is with the WrIteline command
Thank you in advance
Edi
Dim intWeight As Integer
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub frmDataentry_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtDataEnter.Focus()
lblDate.Text = Today
End Sub
Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim CurrentDate As Date
Dim weight As Integer
Dim txtLine As String
Dim txtFileContent As String = ""
'Dim Myline As New String()
txtLine = ""
CurrentDate = lblDate.Text
weight = txtDataEnter.Text
'txtLine += frmInfoTrack.GetFileContent() + ControlChars.CrLf + "#" + CurrentDate + "#" + "," + Str(weight)
txtFileContent = frmInfoTrack.GetFileContent()
'txtLine += txtFileContent + ControlChars.CrLf + "#" + CurrentDate + "#" + "," + Str(weight)
txtLine += txtFileContent + "#" + CurrentDate + "#" + "," + Str(weight)
MessageBox.Show("This is content of file" + frmInfoTrack.GetFileContent())
MessageBox.Show("this is the content of txtline" + txtLine)
FileOpen(1, frmInfoTrack.AppPath + "Note.ini", OpenMode.Output)
'WriteLine(1, CurrentDate, weight)
Writeline(1,txtLine)
FileClose(1)
txtDataEnter.Text = ""
'Debug.WriteLine(frmInfoTrack.GetFileContent())
MessageBox.Show("This is content after writing" + frmInfoTrack.GetFileContent())
txtLine = ""
Exit Sub
End Sub
End Class