473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Listbox is selected the name and corresponding phone number should be should

3
Basically i want to design a membership Name and Telephone List form using the following command buttons.

Edit
Add New;
Update;
Delete;
Cancel;
Save;
Clear, and
Exit

The names and phone numbers of members are stored in a sequential text file called MEMBERS.TXT which i have created.

When the program is loaded, names and telephone numbers should be read from the file and stored in an array or arrays in memory and then, from memory, the names and telephone numbers are displayed in alphabetical names sequence in a list box.


I used two textboxs to hold the Name and the other to hold the Number

When a name in the listbox is selected (clicked) the name and corresponding phone number should be should be displayed in the textboxes but i cant manage to do this.

To change any fields, the user first uses the Edit button to enable the textboxes to be changed.

The user makes the amendments to the textboxes and uses the update button to effect the change in memory. I need your help on this too.

To delete an item, Delete is used. But i dont know how to do this using sequantial Files. Thanks for your help.

Code sofar

Public Class MembersForm

Private Sub ExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Close()
End Sub

Private Sub MembersForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim intButton As Integer, objStreamWriter As System.IO.StreamWriter

'display the form immediately
Me.Show()
'determine if the user wants to create a new file
intButton = MessageBox.Show("Create new File?", "Members Phone List", _
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
'create new sequential acces file, if necessary
If intButton = Windows.Forms.DialogResult.Yes Then
objStreamWriter = System.IO.File.CreateText("Members.txt")
objStreamWriter.Close()
Else
objStreamWriter = System.IO.File.AppendText("Members.txt")
objStreamWriter.Close()
End If

Dim strMembers As String, objStreamReader As System.IO.StreamReader
'load members to listbox
If System.IO.File.Exists("Members.txt") = True Then
objStreamReader = System.IO.File.OpenText("Members.txt")
Do While objStreamReader.Peek <> -1
strMembers = objStreamReader.ReadLine()
Me.MembersListBox.Items.Add(strMembers)
Loop
objStreamReader.Close()
Else
MessageBox.Show("File does not exits.", "Members Phone List", _
MessageBoxButtons.OK, MessageBoxIcon.Information)

End If
End Sub

Private Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click

Dim objStreamWriter As System.IO.StreamWriter
objStreamWriter = System.IO.File.AppendText("Members.txt")

objStreamWriter.Write(Me.NameTextBox.Text.PadRight (30))
'objStreamWriter.Write(Space(5))
objStreamWriter.WriteLine(Me.NumberTextBox.Text.Pa dRight(10))
'objStreamWriter.WriteLine()
objStreamWriter.Close()

Me.NameTextBox.Text = ""
Me.NumberTextBox.Text = ""
Me.NameTextBox.Focus()

End Sub

Private Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
Dim strMembers As String, objStreamReader As System.IO.StreamReader
'update members to memberslistbox
If System.IO.File.Exists("Members.txt") = True Then
objStreamReader = System.IO.File.OpenText("Members.txt")
Me.MembersListBox.Items.Clear()
Do While objStreamReader.Peek <> -1
strMembers = objStreamReader.ReadLine()
Me.MembersListBox.Items.Add(strMembers)
Loop
objStreamReader.Close()
Me.MembersListBox.SelectedIndex = 0

End If
End Sub

Private Sub SaveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveButton.Click
Dim objStreamWriter As System.IO.StreamWriter
objStreamWriter = System.IO.File.AppendText("Members.txt")

objStreamWriter.Write(Me.NameTextBox.Text.PadRight (30))
objStreamWriter.Write(Space(5))
objStreamWriter.Write(Me.NumberTextBox.Text.PadLef t(10))
objStreamWriter.WriteLine()
objStreamWriter.Close()

Me.NameTextBox.Text = ""
Me.NumberTextBox.Text = ""
Me.NameTextBox.Focus()
End Sub

Private Sub MembersListBox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MembersListBox.Click

Me.NameTextBox.Text = MembersListBox.SelectedItem()

End Sub

End Class
Jan 17 '08 #1
0 1345

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Coz | last post by:
Hi all, I'm looking for help again!!! I have been writing a page to update a database but now have another 'silly' problem with listbox's...Grrr... I'm trying to populate the list box with...
4
by: Alienz | last post by:
I have a subform where I have a subform with 20 options to select from. When I set the multiselect property to simple and select multiple options, nothing is stored. I have another table with...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
6
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject...
8
by: tshad | last post by:
I have a string that I read from my database: 1|8|5620|541 These are all values in my ListBox. I want to select each of these items (4 of them - but could be many more). At the moment I am...
1
by: acord | last post by:
Hi, I am having problem to get a value of the selected item from a dropdown listbox. Here is the JS function; function getSelectedItem(objSelect) { alert("in getSelectedItem"); alert...
2
by: remya1000 | last post by:
i'm using VB.NET. i have a table names "EMP". this table contain employee details like Index, empID, First name, Last name, address, phone number etc. while page loads, i need to display Last...
2
by: aiswarya | last post by:
I've a table named student in my database.In it there are 7 columns .Now, in my form, when I click my table name, the name of columns should be displayed in one listbox ie in listbox1. Again, when...
45
by: angelicdevil | last post by:
i have 2 tables 1 is status_type with field name status and other is users with field username and status now i want that the first listbox lists all status from status type ( this i have achieved...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.