Hi, i am writing a mobile application to save some task. In this application i want save the data of task to the text file(*.txt). however, i faced some of the issues that i unable to save data to txt file due to the runtime error on file not exist but i have checked it and the txt file is existed. Hope anybody can help. Here my code as below
Imports System.IO
Public Class Form1
Public showdisplay As New ArrayList
Public Task As New task
Dim showdetails As New showdetails
Private Sub mnuadd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuadd.Click
Task.Write_File(a:=txtTitle.Text, b:=txtDescription.Text, c:=dtpDate.Value)
If txtTitle.Text = " " And txtDescription.Text = " " Then
MessageBox.Show("Please Input Task Title and Task Description")
Else
showdisplay.Add(Task)
ListBox1.Items.Add(Task)
MessageBox.Show("Task Save", "Task Save", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End If
txtTitle.Text = " "
txtDescription.Text = " "
dtpDate.Value = Date.Today
End Sub
The function for Write_file as below
Imports System.IO
Public Class task
Public Title As String
Public Description As String
Public Dates As Date
Public Sub Write_File(ByVal a As String, ByVal b As String, ByVal c As Date)
Title = a
Description = b
Dates = c
Dim writer As IO.StreamWriter = New IO.StreamWriter("MyData.txt\", False)
Dim strwritedata As String
strwritedata = a & "," & b & "," & c
writer.WriteLine(strwritedata)
writer.Close()
End Sub