Allen,
When posting code its "better" to put the code in a Zip file, as .vb files
are normally blocked to ensure you are not attempting to spread a virus. Or
inline like you did here...
Its also "better" to stay in the newsgroup you started, rather then splatter
your message on a number of VB6 newsgroups. Once you have "exhausted" this
group, then I would recommend turning to other .NET groups...
However!
Four comments on your Customer class:
1) Rather then use "Sub Initialize", I would recommend using "Shared Sub
New", as it is called automatically for you. (You don't need to remember to
explicitly call it).
2) Rather then use comments, I would recommend using Regions to delimit
blocks of code.
3) Your class should use Properties instead of accessor methods (GetName,
SetName, GetAddress, SetAddress, GetPhoneNo, and SetPhoneNo). As the data
binding requires Properties.
4) .NET has a predefined "TellAboutSelf" function, its called ToString, you
should override ToString instead of defining your own function.
So your class becomes:
Public Class Customer
#Region " Attributes "
Private m_name As String
Private m_address As String
Private m_phoneNo As String
#End Region
#Region " Data Access Shared Methods "
Shared Sub New()
' TODO: rename CustomerDA.Initialize to New!
' allowing us to remove shared Customer.New...
CustomerDA.Initialize()
End Sub
Public Shared Function Find(ByVal PhoneNo As String) As Customer
Return CustomerDA.Find(PhoneNo)
End Function
Public Shared Function GetAll() As ArrayList
Return CustomerDA.GetAll
End Function
Public Shared Sub Terminate()
CustomerDA.Terminate()
End Sub
#End Region
#Region " Data Access Instance Methods "
Public Sub AddNew()
CustomerDA.AddNew(Me)
End Sub
Public Sub Update()
CustomerDA.Update(Me)
End Sub
Public Sub Delete()
CustomerDA.Delete(Me)
End Sub
#End Region
#Region " Properties "
Public Property Name() As String
Get
Return m_name
End Get
Set(ByVal value As String)
m_name = value
End Set
End Property
Public Property Address() As String
Get
Return m_address
End Get
Set(ByVal value As String)
m_address = value
End Set
End Property
Public Property PhoneNo() As String
Get
Return m_phoneNo
End Get
Set(ByVal value As String)
m_phoneNo = value
End Set
End Property
#End Region
#Region " Tell About Self "
Public Overrides Function ToString() As String
Dim info As String
info = "Name = " & Name & _
", Address = " & Address & _
", Phone No = " & PhoneNo
Return info
End Function
#End Region
#Region " Constructors "
'default constructor
Public Sub New()
End Sub
'constructor (3 parameters)
Public Sub New(ByVal aName As String, ByVal anAddress As String, _
ByVal aPhoneNo As String)
m_name = aName
m_address = anAddress
m_phoneNo = aPhoneNo
End Sub
#End Region
End Class
Then as Ken stated when you bind to the ListBox, you would use something
like:
Dim list As ArrayList
Dim ListBox1 As ListBox
ListBox1.DataSource = list
ListBox1.DisplayMember = "Name"
ListBox1.ValueMember = "PhoneNo"
To get the selected customer from the ListBox you can use the
ListBox.SelectedItem property:
Dim selectedCustomer As Customer =
DirectCast(ListBox1.SelectedItem, Customer)
To get the selected phone number from the ListBox you can use the
ListBox.SelectedValue property:
Dim phoneNo As String = DirectCast(ListBox1.SelectedValue,
String)
Hope this helps
Jay
Allen said:
I am really begining to hate programming.
I have to have this thing done for class and cant seem to get it to do
what
its supose to do.
I have two classes one Customers and one CustomersDA
I have a form that is supose to display customer names in a listbox and
then
have 3 buttons (find, Update and Close) I cant seem to get things to work
the right way. Everyone has had good input but its not helped at all.
I have attached the code for the two classes I have to get this done for
class its making me get behind. If someone out there can please take a
look
at it and help me out. I have tried it all and just cant get it. Once I
see
how it is done it will help me to understand. I really need help bad. I
have
looked for days on how to do it.
Code is pasted below. How do you f'n do this.
Thanks Allen
<<snip>>