In: Computer Science
Create a program in visual basic that allows the user to manage vehicle information including: • License plate number • Owner name • Owner phone number The user interface will be GUI-based providing the following capabilities: • Add up to 100 vehicles • Remove specified vehicles • View a sorted list of all known license plates • View the data for a specified vehicle • Save the database contents into a file • Load a saved database from a file
Solution
Copyable code:
Imports System.IO
Public Class DMV
' Declare the variable
Dim inp As String
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
' Add the textbox data into list box
inp = txtlNum.Text & " " + txtOwnname.Text & " " & txtOwnpho.Text
If (inp <> "") Then
lstData.Items.Add(inp)
End If
lstData.Sorted = True
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
' delete the selected item from a list box
If (lstData.SelectedIndex > 0) Then
lstData.Items.Remove(lstData.SelectedItem. ToString)
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
' Read the data from list box and write it into text file
Dim s As String
Using sw As StreamWriter = New StreamWriter ("DMVDatabase.txt")
For Each s In lstData.Items
sw.WriteLine(s)
Next s
End Using
MsgBox("Data saved into file!")
End Sub
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
' Clear the list box
lstData.Items.Clear()
' Read the data from text file and write it into list box
Using sr As StreamReader = New StreamReader ("DMVDatabase.txt")
Dim line As String
' Read and lines from the file
line = sr.ReadLine()
While (line <> Nothing)
lstData.Items.Add(line)
line = sr.ReadLine()
End While
End Using
End Sub
End Class