Well here goes:
Typically when I am assigned a new project, I break it down into what parts I am going to need to complete it. For your problem statement I determined that I would need 2 Labels (to designate which text box is which) 2 Text boxes (for entering MemberName and MemberNumber) a ListBox (I like to use Listviews myself, but I am using a listbox since that was what you said you were using) and finally 8 buttons, one for each operation you wanted to do.
Now that we have drawn those objects onto our form, and before we write any code, lets put some proper names on the Controls so we don't get confused as the project gains more complexity (this program is rather simple, if I didn't use good naming schemes, my 2 year project at work would really be difficult to work on):
when naming controls, try to designate what control it is with the name by adding three lower case letters to the begining. I named the objects as followed:
txtMemberName, txtMemberNumber, lblMemeberName, lblMemberNumber, lstNames, btnEdit, btnAdd, btnUpdate, btnDelete, btnCancel, btnSave, btnClear, btnExit.
Now that we have our form drawn up, lets take a crack at coding functionality.
So I wrote a few custom Subroutines (if you didn't know how to do this, type in Sub Bob() and hit enter [should auto put in the end sub] and now you can call the code in the Bob subroutine from anywhere else on the form (Form1_Load etc). This comes in handy when you have a few lines of code that will get repeated a lot such as the code to repopulate the listBox.
Read the commenting under each function for the specifics, but here is a breif description of each function I wrote:
grabData(fileName as String) - This function is used to grab the names and numbers out of the fileName supplyed. If that filename does not exist the program will crash. I created a file with 2 lines in it, first line was name, second line was number and named it MEMBERS.TXT and saved it to the bin folder of my project to avoid the crash. If you want to fix the crash, you need to handle for no data in the fillListBox function.
Note on grabData - If you notice, I use the ReDim Preserve keywords on my two arrays (at the top they are declared as MemberName(0) and MemberNumber(0) which normally meens they can only hold 1 value in cell (0). Well since I wanted this program to be able to handle any number of members, the ReDim Preserve Array(Array.Length) adds on a new cell. Heres how:
When I declare an array i do this Dim Arr(10) as integer, I can now store values in Arr(0), Arr(1) ... Arr(10). So the Length of Arr is 11. So if I say ReDim Arr(Arr.Length) I am really saying ReDim Arr(11) which increases the size by 1.
Normally when you do a reDim it erases the values that used to be in the array, but when you include the Preserve keyword, it saves them.
writeVarsToFile(MName() as String, MNumber() as String, fileName as string) - This function writes sequentially writes each MemberName and MemberNumber from the two arrays supplied to it to the fileName you pass it.
fillListBox(MName() as String, LB as ListBox) - This function fills the ListBox you pass it with every name in the passed MName array. Assuming that there is a MemberNumber for each MemberName, we will use ListBox.SelectedIndex in the end to know which item in the array we have selected.
removeMember(index as integer) - This function removes a member from the array. Note: You have to save the file with the save button to update the text file for any changes. If you notice, to remove an item, I just shift every value up one by saying Array(x) = Array(x+1) at the end, I use ReDim Preserve to shrink the array length down by 1 and remove the now duplicated value at the end
addMember(MName as String, MNumber as String) - This function simply adds a new cell to the array and puts Mname and Mnumber in.
The rest of the code is event driven.
On Load I read the text file and populate the Listbox with the data now in memory (I am not handling for the file not existing, you should add that)
When the listbox calls SelectedIndexChanged (when you select something new) the Textboxes up top are updated to display the information underneath the arrays at that selected index (since we sync up the MemberName array with the listBox items, SelectedIndex 0 = Array(0).
When the user clicks Add New, the text boxes are enabled and cleared. You can add in a new name and number and click the add New button again to add it to the list. If you look at the code under the add new button, I set a boolean called AddNewMode to true on the first click, and set it back to false on the second click.
When a user selects a new item on the listbox, it sets AddNewMode and EditMode to false incase you were in the middle of making changes and decided to stop.
I hope this program helps (code included in next post). I didn't finish all the buttons code because I am not sure exactly what each button needs to do, but you can probably just modify this code to get it to do everything you need.
If you have anymore questions, or don't understand any parts of this code, just reply back I will gladly and indepthly explain any part of it to help you learn.
Sean Campbell - Programmer / Musician / Life Philosopher
check out my Music site http://www.jamjunky.com/firesickle