Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

VISUAL BASIC- VISUAL BASIC- create a program for managing a \"To Do\" list. The

ID: 3823501 • Letter: V

Question

VISUAL BASIC-

VISUAL BASIC-

create a program for managing a "To Do" list. The program will need to read and update a text file named ToDoList.txt. The record structure of the file must be: 1) sort order, 2) task name and 3) desired completion date.

When the program starts, it should read the contents file into a structure. The information should then be displayed in a data grid view. The data should be initially sorted by the sort order value. Afterwards, the user should be able to click on a column name to sort the data by that specific column.

The user should be able to add, update and delete tasks. The methods to implement these features are up to you. Please note that each value (sort order, task name and desired completion date) should be saved as a string value.

The program must use StreamReader and StreamWriter objects. The program must also contain exception handling for a missing input file. If the input file is not found, the user should be informed and still be allowed to use the program (i.e. do not automatically close the program).

THIS IS THE CODE I CURRENTLY HAVE, BUT I AM GETTING THE ERROR: "NO ROW CAN BE ADDED TO A DATAGRIDVIEW CONTROL THAT DOES NOT HAVE COLUMNS. COLUMNS MUST BE ADDED FIRST. HOW DO I GO ABOUT ADDING COLUMNS?

Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Using fileReader As StreamReader = New StreamReader("C:Users*****DesktopToDoList.txt") 'provide correct file path here
Dim fileLine As String = ""
Dim index As Integer = 0
Dim temp(3) As String 'A temp array to store each row at a time (3 columns)
fileLine = fileReader.ReadLine()
While (fileLine <> Nothing) 'read file until the end of the file
temp = fileLine.Split(CChar(",")) 'split the file line with ',' delimeter
'temp(0) contains Sorting Order, temp(1) contains Task Name, temp(2) contains Desired Date
dgvOutput.Rows.Add(temp(0), temp(1), temp(2))
fileLine = fileReader.ReadLine()
End While
End Using

Catch err As Exception
'let the user know if any error/exception occurs
MessageBox.Show("Error: " + err.Message)
End Try
End Sub

Private Sub saveList()
Try
Using fileWriter As StreamWriter = New StreamWriter("D:ToDoList.txt") 'provide correct file path here
For i As Integer = 0 To dgvOutput.Rows.Count - 1 Step +1
For j As Integer = 0 To dgvOutput.Columns.Count - 1 Step +1
fileWriter.Write(dgvOutput.Rows(i).Cells(j).Value.ToString + ",")
Next
fileWriter.WriteLine()
Next
fileWriter.Close()
End Using

Catch err As Exception
'let the user know if any error/exception occurs
MessageBox.Show("Error: " + err.Message)
End Try
End Sub

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
dgvOutput.Rows.Add("", "", "")
End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
Dim RowIndex As Integer
For i As Integer = 0 To dgvOutput.SelectedCells.Count - 1
RowIndex = dgvOutput.SelectedCells.Item(i).RowIndex
Next

If RowIndex < 0 Then 'if row selected then alert the user
MsgBox("Please select any row to delete !")
Else
dgvOutput.Rows.RemoveAt(RowIndex)
MsgBox("Selected row has been deleted !")
End If
End Sub

Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
saveList()
MsgBox("Data saved to file successfully.")
End Sub
End Class

Explanation / Answer

utilizing System;

utilizing System.IO;

open fixed class Program {

open static void Main()

{

DirectoryInfo dInfo = new DirectoryInfo(@"C:******");

DirectoryInfo[] d = dInfo.GetDirectories("*", SearchOption.TopDirectoryOnly);

Console.WriteLine("{0} subdirectories:", dInfo.FullName);

foreach (DirectoryInfo subDir in d)

{

Console.WriteLine(" {0}", subDir.Name);

}

FileInfo[] f = dInfo.GetFiles();

Console.WriteLine("files:");

foreach (FileInfo record in f)

{

Console.WriteLine(" {0} ({1} bytes)", file.Name, file.Length);

}

FileInfo F = new FileInfo(@"C:Windows********");

on the off chance that (F.Exists)

{

Console.WriteLine("Filename: {0}", theF.Name);

Console.WriteLine("Path: {0}", theF.FullName);

DirectoryInfo Dir = new DirectoryInfo(@"C:Windows**************");

Console.WriteLine("Directory: {0}", Dir.FullName);

foreach (FileInfo record in Dir.GetFiles())

{

Console.WriteLine("File: {0}, file.Name);

DriveInfo[] d = DriveInfo.GetDrives();

foreach (DriveInfo drive in drives)

{

Console.WriteLine("Drive: {0}", d.Name);

Console.WriteLine("Type: {0}", d.DriveType);

Diminish record As System.IO.File

Diminish peruser as System.IO.StreamReader

Diminish line As String

peruser = file.OpenText("c:*****")

'presently circle through each line

While reader.Peek <> - 1

line = reader.ReadLine()

Presently check for your particular word

In the event that line.Contains("END") Then

Msgbox("SUCCESS")

'How would I erase - > line

Else

'Accomplish something else here

Msgbox("TRY AGAIN")

End If

End While

reader.Close()

}

}