Computer Science Homework Solutions
Problem
#129507

Menu Driven Program - Visual Basic

name and phone numbers should be read into the program in "memberphones.txt" and should be displayed in a listbox when the form is loaded

to delete a person, they should be highlighted and the delete button should delete them from the list box and array

to modify a person, they should highlight the person and change the attributes and use the "modify" menu option to save the change

to add a person, type the name and number and select "add"

Lastly, hit exit and the program should write out the updated member name and phone numbers to a new file. I'm almost done - I can't find out how to add/delete or modify names and numbers and save them in the memory space for output into a text file.

Attached file(s):
Attachments
MEMBERPHONES.TXT  View File
code.txt  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

code.txt
Structure MemeberInfo
Dim Membername As String
Dim Phonenumber As String
End Structure
Dim Members(20) As MemeberInfo
Dim n, I As Integer
Dim index As Integer

Dim num As Integer



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DisplayMem()



End Sub




Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click

ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
' Members(index).Membername.RemoveAt(ListBox1.SelectedIndex)
DisplayMem()

'Dim inputfile As IO.StreamReader
'inputfile = IO.File.OpenText("memberphones.txt")
' index = 0
' Do While (Members(index).Membername <> ListBox1.SelectedIndex)
'Members(index).Membername = inputfile.ReadLine
' Members(index).Phonenumber = inputfile.ReadLine
' Loop
' index = index + 1




End Sub

Private Sub Add2_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add2.Click
ListBox1.Items.Add(TextBox1.Text)
ListBox1.Items.Add(TextBox2.Text)





End Sub

Private Sub Modify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Modify.Click

ListBox1.Items(ListBox1.SelectedIndex) = TextBox1.Text
Members(ListBox1.SelectedIndex).Membername = TextBox1.Text
Members(ListBox1.SelectedIndex).Phonenumber = TextBox2.Text
End Sub




Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
TextBox1.Text = ListBox1.Items(ListBox1.SelectedIndex)
TextBox2.Text = (Members(ListBox1.SelectedIndex).Phonenumber)



End Sub

Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click


Dim outputfile As IO.StreamWriter
outputfile = IO.File.CreateText("newmembers.txt")
Dim index As Integer
index = 0
For index = 0 To 7
outputfile.WriteLine(Members(index).Membername)
outputfile.WriteLine(Members(index).Phonenumber)
Next
outputfile.Flush()

End Sub

' Sub Delete()
' For index = 0 To 7
' If (Members(index) < Members(index + 1)) Then
' temps = memebers(index)
' End If
' Next
' End Sub

Sub DisplayMem()
Dim inputfile As IO.StreamReader

inputfile = IO.File.OpenText("memberphones.txt")
Dim num As Integer



For index = 0 To 7
If index < 8 Then
Members(index).Membername = inputfile.ReadLine
Members(index).Phonenumber = inputfile.ReadLine
ListBox1.Items.Add(Members(index).Membername)
Else
index = index + 1
End If
Next
'For index = 0 To 7
'ListBox1.Items.Add(Members(index).Membername)
''ListBox1.Items.Add(Members(index).Phonenumber)

End Sub
Solution
What is this?
By OTA - Overall OTA Rating
Purchase Cost Now
$2.19 CAD (was ~$31.92)
Included in Download
  • Plain text response
  • Attached file(s):
    • MenuDrivenprogram.zip
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
Browse