I have a form with a 2 textboxes and a listbox, The data is read in by a
file called "memberphones" The listnbox lists names in this way
(lastname,first name) sorted by the last name. the textboxes have the
"lastname,first name" and the phone in the other one. Now I am stumpped
about how to write the instrucution to modify a record of the arraylist.
here is the whole code.
Imports Microsoft.VisualBasic
Imports System.IO
Imports System.Collections
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents mnuModify As System.Windows.Forms.MenuItem
Friend WithEvents mnuAdd As System.Windows.Forms.MenuItem
Friend WithEvents mnuDelete As System.Windows.Forms.MenuItem
Friend WithEvents mnuExit As System.Windows.Forms.MenuItem
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents lstNames As System.Windows.Forms.ListBox
Friend WithEvents txtName As System.Windows.Forms.TextBox
Friend WithEvents txtPhone As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.lstNames = New System.Windows.Forms.ListBox
Me.txtName = New System.Windows.Forms.TextBox
Me.txtPhone = New System.Windows.Forms.TextBox
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.mnuModify = New System.Windows.Forms.MenuItem
Me.mnuAdd = New System.Windows.Forms.MenuItem
Me.mnuDelete = New System.Windows.Forms.MenuItem
Me.mnuExit = New System.Windows.Forms.MenuItem
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'lstNames
'
Me.lstNames.Location = New System.Drawing.Point(56, 16)
Me.lstNames.Name = "lstNames"
Me.lstNames.Size = New System.Drawing.Size(208, 160)
Me.lstNames.Sorted = True
Me.lstNames.TabIndex = 0
'
'txtName
'
Me.txtName.Location = New System.Drawing.Point(128, 192)
Me.txtName.Name = "txtName"
Me.txtName.Size = New System.Drawing.Size(136, 20)
Me.txtName.TabIndex = 1
Me.txtName.Text = ""
'
'txtPhone
'
Me.txtPhone.Location = New System.Drawing.Point(128, 224)
Me.txtPhone.Name = "txtPhone"
Me.txtPhone.Size = New System.Drawing.Size(136, 20)
Me.txtPhone.TabIndex = 2
Me.txtPhone.Text = ""
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New
System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.mnuExit})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New
System.Windows.Forms.MenuItem() {Me.mnuModify, Me.mnuAdd, Me.mnuDelete})
Me.MenuItem1.Text = "Update"
'
'mnuModify
'
Me.mnuModify.Index = 0
Me.mnuModify.Text = "&Modify"
'
'mnuAdd
'
Me.mnuAdd.Index = 1
Me.mnuAdd.Text = "&Add"
'
'mnuDelete
'
Me.mnuDelete.Index = 2
Me.mnuDelete.Text = "&Delete"
'
'mnuExit
'
Me.mnuExit.Index = 1
Me.mnuExit.Text = "Exit"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 192)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(96, 16)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Name:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(24, 224)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(96, 16)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Phone:"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtPhone)
Me.Controls.Add(Me.txtName)
Me.Controls.Add(Me.lstNames)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Structure member
Dim name As String
Dim phone As String
End Structure
Dim memberarray As New ArrayList
Dim membership As member
Dim fv As StreamReader = File.OpenText("memberphones.txt")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
memberarray = read_file(memberarray)
list_members(memberarray)
fv.Close()
End Sub
Private Function read_file(ByVal array As ArrayList) As ArrayList
Dim icounter As Integer 'iterates loop
Do
membership.name = fv.ReadLine
membership.phone = fv.ReadLine
array.Add(membership)
icounter = icounter + 1
Loop Until fv.Peek = -1
Return array
End Function
Private Sub list_members(ByVal memberarray As ArrayList)
Dim member_counter As Integer
lstNames.Items.Clear()
For Each membership In memberarray
lstNames.Items.Add(membership.name)
Next
End Sub
Private Sub lstNames_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lstNames.SelectedIndexChanged
Dim x As member
For Each membership In memberarray
If membership.name.ToString() = lstNames.Items
(lstNames.SelectedIndex).ToString() Then
txtName.Text = membership.name
txtPhone.Text = membership.phone
End If
Next
End Sub
Private Sub mnuAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuAdd.Click
Dim fr As StreamWriter = File.AppendText("memberphones.txt")
membership.name = txtName.Text
membership.phone = txtPhone.Text
fr.WriteLine(membership.name)
fr.WriteLine(membership.phone)
fr.Close()
list_members(memberarray)
End Sub
Private Sub mnuDelete_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles mnuDelete.Click
memberarray.RemoveAt(lstNames.SelectedIndex)
list_members(memberarray)
End Sub
Private Sub mnuModify_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles mnuModify.Click
index = lstNames.SelectedIndex
membership.name = txtName.Text
membership.phone = txtPhone.Text
************************************************** **********************
CType(memberarray(lstnames.items(lstnames.selected index),
member).phone = txtPhone.Text
I have tried every different derivitive of this and nothing seems to
work, Is there something I am doing wrong? Or is there something else I
shoud try??
JOhn 2 1369
You're holding value types within a reference type... http://www.knowdotnet.com/articles/boxedstructures.html
"RBCC" <rb**@vei.net> wrote in message
news:Xn*****************************@207.46.248.16 ... I have a form with a 2 textboxes and a listbox, The data is read in by a file called "memberphones" The listnbox lists names in this way (lastname,first name) sorted by the last name. the textboxes have the "lastname,first name" and the phone in the other one. Now I am stumpped about how to write the instrucution to modify a record of the arraylist. here is the whole code.
Imports Microsoft.VisualBasic Imports System.IO Imports System.Collections
Public Class Form1 Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New() MyBase.New()
'This call is required by the Windows Form Designer. InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub
'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem Friend WithEvents mnuModify As System.Windows.Forms.MenuItem Friend WithEvents mnuAdd As System.Windows.Forms.MenuItem Friend WithEvents mnuDelete As System.Windows.Forms.MenuItem Friend WithEvents mnuExit As System.Windows.Forms.MenuItem Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents lstNames As System.Windows.Forms.ListBox Friend WithEvents txtName As System.Windows.Forms.TextBox Friend WithEvents txtPhone As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.lstNames = New System.Windows.Forms.ListBox Me.txtName = New System.Windows.Forms.TextBox Me.txtPhone = New System.Windows.Forms.TextBox Me.MainMenu1 = New System.Windows.Forms.MainMenu Me.MenuItem1 = New System.Windows.Forms.MenuItem Me.mnuModify = New System.Windows.Forms.MenuItem Me.mnuAdd = New System.Windows.Forms.MenuItem Me.mnuDelete = New System.Windows.Forms.MenuItem Me.mnuExit = New System.Windows.Forms.MenuItem Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.SuspendLayout() ' 'lstNames ' Me.lstNames.Location = New System.Drawing.Point(56, 16) Me.lstNames.Name = "lstNames" Me.lstNames.Size = New System.Drawing.Size(208, 160) Me.lstNames.Sorted = True Me.lstNames.TabIndex = 0 ' 'txtName ' Me.txtName.Location = New System.Drawing.Point(128, 192) Me.txtName.Name = "txtName" Me.txtName.Size = New System.Drawing.Size(136, 20) Me.txtName.TabIndex = 1 Me.txtName.Text = "" ' 'txtPhone ' Me.txtPhone.Location = New System.Drawing.Point(128, 224) Me.txtPhone.Name = "txtPhone" Me.txtPhone.Size = New System.Drawing.Size(136, 20) Me.txtPhone.TabIndex = 2 Me.txtPhone.Text = "" ' 'MainMenu1 ' Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.mnuExit}) ' 'MenuItem1 ' Me.MenuItem1.Index = 0 Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuModify, Me.mnuAdd, Me.mnuDelete}) Me.MenuItem1.Text = "Update" ' 'mnuModify ' Me.mnuModify.Index = 0 Me.mnuModify.Text = "&Modify" ' 'mnuAdd ' Me.mnuAdd.Index = 1 Me.mnuAdd.Text = "&Add" ' 'mnuDelete ' Me.mnuDelete.Index = 2 Me.mnuDelete.Text = "&Delete" ' 'mnuExit ' Me.mnuExit.Index = 1 Me.mnuExit.Text = "Exit" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(24, 192) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(96, 16) Me.Label1.TabIndex = 3 Me.Label1.Text = "Name:" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(24, 224) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(96, 16) Me.Label2.TabIndex = 4 Me.Label2.Text = "Phone:" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.txtPhone) Me.Controls.Add(Me.txtName) Me.Controls.Add(Me.lstNames) Me.Menu = Me.MainMenu1 Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False)
End Sub
#End Region
Structure member Dim name As String Dim phone As String End Structure
Dim memberarray As New ArrayList Dim membership As member Dim fv As StreamReader = File.OpenText("memberphones.txt") Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load memberarray = read_file(memberarray) list_members(memberarray) fv.Close()
End Sub Private Function read_file(ByVal array As ArrayList) As ArrayList Dim icounter As Integer 'iterates loop
Do membership.name = fv.ReadLine membership.phone = fv.ReadLine array.Add(membership) icounter = icounter + 1 Loop Until fv.Peek = -1 Return array End Function Private Sub list_members(ByVal memberarray As ArrayList)
Dim member_counter As Integer lstNames.Items.Clear()
For Each membership In memberarray lstNames.Items.Add(membership.name) Next End Sub
Private Sub lstNames_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstNames.SelectedIndexChanged Dim x As member For Each membership In memberarray If membership.name.ToString() = lstNames.Items (lstNames.SelectedIndex).ToString() Then txtName.Text = membership.name txtPhone.Text = membership.phone End If Next End Sub
Private Sub mnuAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAdd.Click Dim fr As StreamWriter = File.AppendText("memberphones.txt") membership.name = txtName.Text membership.phone = txtPhone.Text fr.WriteLine(membership.name) fr.WriteLine(membership.phone) fr.Close() list_members(memberarray)
End Sub
Private Sub mnuDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDelete.Click
memberarray.RemoveAt(lstNames.SelectedIndex) list_members(memberarray)
End Sub
Private Sub mnuModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuModify.Click index = lstNames.SelectedIndex
membership.name = txtName.Text membership.phone = txtPhone.Text ************************************************** ********************** CType(memberarray(lstnames.items(lstnames.selected index), member).phone = txtPhone.Text I have tried every different derivitive of this and nothing seems to work, Is there something I am doing wrong? Or is there something else I shoud try??
JOhn
William:
So you are saying is that this can't be done? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kurt Watson |
last post by:
I’m having a different kind of problem with Hotmail when I sign in it
says, "Web Browser Software Limitations
Your Current Software Will Limit Your Ability to Use Hotmail
You are using a web...
|
by: Alan Bashy |
last post by:
Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help...
|
by: x muzuo |
last post by:
Hi guys,
I have got a prob of javascript form validation which just doesnt work
with my ASP code. Can any one help me out please.
Here is the code:
{////<<head>
<title>IIBO Submit Page</title>...
|
by: tyler_durden |
last post by:
thanks a lot for all your help..I'm really appreciated...
with all the help I've been getting in forums I've been able to continue
my program and it's almost done, but I'm having a big problem that...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: Joner |
last post by:
Hello,
I'm having trouble with a little programme of mine where I connect to
an access database. It seems to connect fine, and disconnect fine, but
then after it won't reconnect, I get the error...
|
by: sd00 |
last post by:
Hi all, can someone give me some coding help with a problem that
*should* be really simple, yet I'm struggling with.
I need the difference between 2 times (Target / Actual)
However, these times...
|
by: PEB |
last post by:
POSTING GUIDELINES
Please follow these guidelines when posting questions
Post your question in a relevant forum
Do NOT PM questions to individual experts - This is not fair on them and...
|
by: 2Barter.net |
last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA
Inbox
Reply
Reply to all
Forward
Print
Add 2Barter.net to Contacts list
Delete this message
Report phishing
Show original
|
by: tabani |
last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable...
The error arrives from option 'a' it asks...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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,...
|
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,...
|
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...
| |