Create new Customer class dynamically in vb 2010

Associate
Joined
31 Dec 2002
Posts
458
Hi, I am stuck for the last week trying to understand what is probably staight forward for most of you. In vb 2010 I am trying to do the following:

Have a customer class with the following properties so:

public class Customer
public property name as string
public property bill as string
public property usage as string
end class

I want a sub routine that creates a new instance of the Customer class after a customer has entered their name in a textbox,taking the name from a textbox as the parameter, something like:

private sub addCustomer(name as string)
dim name as new Customer
newCustomer.name = txtName.text
newCustomer.usage = txtUsage.text
newCustomer.bill = txtBill.text

end sub

I feel I may be close but would appreciate it if someone could give me a steer. I have omitted the form start and end class code and other code, but it is just the standard prepopulated code. I have also created the customer class by adding new class. thanks
 
the trouble is, what I need to do is have a customer object that is named after that particular customer. I do not know before the app runs what the customers name will be. I have text boxes for them to enter their name, account number, usage, etc.

I want to be able to retrieve this information later so that next time they login they will be able to view their previous bill and usage information. I originally was using an arraylist() which worked fine with .add to bring the textbox text into the array. The problem is that for each customer that is added to the array their information is added sequentially and there is no index. The same customer could also have multiple sets of data. If I had an index I could then keep track of it and retrieve their information that way. I could use a multi-dimension array, but this is hard to navigate and conceptualise (for me anyway). I cannot use a database for this app.

the app is for me to learn from, not a production app as I am fairly new to programming.
 
I know it won't persist apart from dumping to a text file at the moment. I am using it to learn about using simple classes and retrieving and storing information in them. It is a simple customer database if you like where users can enter their consumption of electricity for example and for the program to work out their unit costs, total up a bill and present it to them. They can then login later and view previous bills. I know a database will be the ideal solution but want to know how to create a new instance of my customer class, based off customer name.

Thanks. Hope that makes sense:)
 
Here you go:

Code:
Public Class frmClassTest

    Dim custName As String = txtName.Text

    Private Sub addCustomer(name As customer)
        Dim newCustomer As New customer

    End Sub


    Private Sub btnEnter_Click(sender As System.Object, e As System.EventArgs) Handles btnEnter.Click

        addCustomer(custName)
        newCustomer.name = txtName.Text
        newCustomer.account = txtAccount.Text
        newCustomer.usage = txtUsage.Text
        newCustomer.type = txtType.Text

        txtDisplayClass.Text = newCustomer.name & vbNewLine & newCustomer.account & vbNewLine * newCustomer.usage _
            vbnewline & newCustomer.type




    End Sub

    Private Sub frmTextTest_Load(sender As Object, e As System.EventArgs) Handles Me.Load

    End Sub

    
End Class

Code:
Public Class customer
    Private Property name As String
    Private Property accountNumber As String
    Private Property usage As String
    Private Property custType As String

End Class
 
Last edited:
Back
Top Bottom