473,766 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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_Clic k(ByVal sender As Object, ByVal e As System.EventArg s) Handles ExitButton.Clic k
Close()
End Sub

Private Sub MembersForm_Loa d(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load

Dim intButton As Integer, objStreamWriter As System.IO.Strea mWriter

'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", _
MessageBoxButto ns.YesNo, MessageBoxIcon. Exclamation, MessageBoxDefau ltButton.Button 2)
'create new sequential acces file, if necessary
If intButton = Windows.Forms.D ialogResult.Yes Then
objStreamWriter = System.IO.File. CreateText("Mem bers.txt")
objStreamWriter .Close()
Else
objStreamWriter = System.IO.File. AppendText("Mem bers.txt")
objStreamWriter .Close()
End If

Dim strMembers As String, objStreamReader As System.IO.Strea mReader
'load members to listbox
If System.IO.File. Exists("Members .txt") = True Then
objStreamReader = System.IO.File. OpenText("Membe rs.txt")
Do While objStreamReader .Peek <> -1
strMembers = objStreamReader .ReadLine()
Me.MembersListB ox.Items.Add(st rMembers)
Loop
objStreamReader .Close()
Else
MessageBox.Show ("File does not exits.", "Members Phone List", _
MessageBoxButto ns.OK, MessageBoxIcon. Information)

End If
End Sub

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

Dim objStreamWriter As System.IO.Strea mWriter
objStreamWriter = System.IO.File. AppendText("Mem bers.txt")

objStreamWriter .Write(Me.NameT extBox.Text.Pad Right(30))
'objStreamWrite r.Write(Space(5 ))
objStreamWriter .WriteLine(Me.N umberTextBox.Te xt.PadRight(10) )
'objStreamWrite r.WriteLine()
objStreamWriter .Close()

Me.NameTextBox. Text = ""
Me.NumberTextBo x.Text = ""
Me.NameTextBox. Focus()

End Sub

Private Sub UpdateButton_Cl ick(ByVal sender As Object, ByVal e As System.EventArg s) Handles UpdateButton.Cl ick
Dim strMembers As String, objStreamReader As System.IO.Strea mReader
'update members to memberslistbox
If System.IO.File. Exists("Members .txt") = True Then
objStreamReader = System.IO.File. OpenText("Membe rs.txt")
Me.MembersListB ox.Items.Clear( )
Do While objStreamReader .Peek <> -1
strMembers = objStreamReader .ReadLine()
Me.MembersListB ox.Items.Add(st rMembers)
Loop
objStreamReader .Close()
Me.MembersListB ox.SelectedInde x = 0

End If
End Sub

Private Sub SaveButton_Clic k(ByVal sender As Object, ByVal e As System.EventArg s) Handles SaveButton.Clic k
Dim objStreamWriter As System.IO.Strea mWriter
objStreamWriter = System.IO.File. AppendText("Mem bers.txt")

objStreamWriter .Write(Me.NameT extBox.Text.Pad Right(30))
objStreamWriter .Write(Space(5) )
objStreamWriter .Write(Me.Numbe rTextBox.Text.P adLeft(10))
objStreamWriter .WriteLine()
objStreamWriter .Close()

Me.NameTextBox. Text = ""
Me.NumberTextBo x.Text = ""
Me.NameTextBox. Focus()
End Sub

Private Sub MembersListBox_ Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles MembersListBox. Click

Me.NameTextBox. Text = MembersListBox. SelectedItem()

End Sub

End Class
Jan 17 '08 #1
0 1372

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

Similar topics

5
5253
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 static values pre-programmed into the page and then set the listbox value to that of the one contained in the database for that particular record the code I'm using is - <select name="SelectGarage">
4
2769
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 fieldID and fieldtype and I would like for evertime something is selected in the listbox for a new entry to be created with that fieldtype for the corresponding fieldID which is linked to the main form. Basically, how do I get info from the listbox...
4
5370
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), column4 (Forename) and column5 (title). Columns 3,4 and 5 are not shown in the list box only the first two. DOB Name: &" "&&", "&
6
2138
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 "string" in google comp.lang.c archives.Hope this helps.Hope I am not bothering any one. am I? =================================Start=========================== subject: Return to Start of Line? Question: I'd like printf, the next printf, to return...
8
1896
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 doing the following: Dim a() As String Dim j As Integer a = JobCategoriesSelected.Split("|") ' Where JobCategoriesSelected is set to 1|8|5620|541 For j = 0 To a.GetUpperBound(0)
1
25732
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 (objSelect.length); alert (objSelect.value);
2
2597
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 name First name of all employees in a listbox. and if i select any employee name from listbox and press "EDIT" button, then i need to display the employee details for that particular employee what we selected in listbox. right now what i did is...
2
1182
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 I click one column name in listbox1,the corresponding attributes of that column should be displayed in listbox2. If the column selected is of varchar type, then the items populated in listbox should be in single quotes. If the column selected is...
45
6895
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 with php ) and based on selection of the value in listbox 1 the corresponding data in table users be loaded in listbox 2 . i have achieved this by using a button in php but i want tht it operate without submit button and no page refreshing ...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.