Hi Guys
As I said in my prior post I am trying to get to grips with Classes and how to use them "efficiently", So bearing this in mind I decided to create a small class driven application.
I am struggling to understand how I can "use" this new instance of this user somewhere else.
Test Data was
Name : Joe
username : JoeBloggs
Password : JoesPassword
Then
Name : John
Username : JohnDoe
Password : JohnsPassword
Now this updates the listbox with Joe and John in each row.
The Form Code is. 3 Textboxes, 1 Button , 1 Listbox, 2Labels.
Which is handled by this class.Code:Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If (txtName.Text = "") Then MsgBox("ERROR ENTER CLASS NAME") Else 'Create a new user object. I tried to create a "unique" object name by passing the txtName.text value but it throws errors getName is not member of string.. 'Dim txtName.text As New user Dim newObject As New user newObject.setDetails(txtUsername.Text, txtPassword.Text, txtName.Text) lstUsers.Items.Add(newObject.getName()) End If End Sub Private Sub lstUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstUsers.SelectedIndexChanged Dim users As user users.getLogins(lstUsers.SelectedItem) End Sub End Class
Now this works and updates the listbox with the new instance of the user but how can I use that instance from the listBox control to retrieve that users details??Code:Public Class user Dim name As String Dim username As String Dim password As String Public Sub setDetails(ByVal argusername As String, ByVal argpassword As String, ByVal argName As String) name = argName username = argusername password = argpassword End Sub Public Function getName() Return name End Function Public Function getLogins(ByVal userObject As Object) Form1.Label1.Text = username Form1.Label2.Text = password Return Nothing End Function End Class
Many Thanks Barra.
PS If you needed clearer clarification on what i am trying to do, Please ask![]()




Reply With Quote