Hi,

In the following code (Class & Form1), I'm trying to figure out the following:

- Create an array that stores the 'Clients' (first name, last name, account number)
- 'Button List' the array with the (First Name , Last Name , Array Value , Account Balance)

I attached the output and the code to make it more clear and I appreciate the help.

Thank you.


This is the Class code:

Public Class BankAccountClass
    'Private "Protected" variable
    Private FName As String
    Private LName As String
    Private AcctNum As String
    Private Bal As Decimal

    Public Property FirstName As String
        Get
            Return FName
        End Get
        Set(ByVal value As String)
            FName = value
        End Set
    End Property

    Public Property LastName As String
        Get
            Return LName
        End Get
        Set(ByVal value As String)
            LName = value
        End Set
    End Property

    Public Property AccountNumber As String
        Get
            Return AcctNum
        End Get
        Set(ByVal value As String)
            AcctNum = value
        End Set
    End Property

    Public Property Balance As Decimal
        Get
            Return Bal
        End Get
        Set(ByVal value As Decimal)
            Bal = value
        End Set
    End Property
End Class

And here is the Form1 Code

Public Class Form1
    Public ClientRecords(-1) As BankAccountClass
    Private Sub ButtonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAdd.Click
        Dim AClient As New BankAccountClass
        AClient.FirstName = InputBox("Enter first name", "Enter")
        AClient.LastName = InputBox("Enter last name", "Enter")
        AClient.AccountNumber = InputBox("Deposit Amount", "Bank Account Program")
        ReDim Preserve ClientRecords(ClientRecords.Length)
        ClientRecords(ClientRecords.Length - 1) = AClient
        ' BankCustomer.AccountNumber = Integer.Parse(AllCustomers.Length + 1)
    End Sub

    Private Sub ButtonDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDisplay.Click

    End Sub

    Private Sub ButtonList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonList.Click
        TextBoxDisplay.Text = ""
        TextBoxDisplay.Text &= "Last Name" & vbTab & "First Name" & vbTab & "Array Number" & vbTab & "Account" & vbCrLf
        For Each MyStudents As BankAccountClass In ClientRecords

            TextBoxDisplay.Text &= MyStudents.LastName & vbTab & vbTab & MyStudents.FirstName & vbTab & vbTab & "Array Value" & vbTab & MyStudents.AccountNumber & vbCrLf


        Next
    End Sub
End Class

Instead of doing repeated ReDims, you could just declare a list of the required type then "Add" new items.

Dim ClientRecords As New List(Of BankAccountClass)

Dim AClient As New BankAccountClass
AClient.FirstName = InputBox("Enter first name", "Enter")
AClient.LastName = InputBox("Enter last name", "Enter")
AClient.AccountNumber = InputBox("Deposit Amount", "Bank Account Program")

ClientRecords.Add(AClient)

Edited 4 Years Ago by Reverend Jim: n/a

But how can I "List" the item in the array with the position of the item, like each Client with his/her array position (1,2,3, etc) ?

Or you could use a dictionary.

Dim ClientRecords As New Dictionary(Of Integer, BankAccountClass)
Dim AClient As BankAccountClass

'add 5 new items

For i As Integer = 1 to 5
    AClient = New BankAccountClass
    AClient.FirstName = InputBox("Enter first name", "Enter")
    AClient.LastName = InputBox("Enter last name", "Enter")
    AClient.AccountNumber = InputBox("Deposit Amount", "Bank Account Program")
    AClient.Add(i,AClient)
Next

You can index ClientRecords like an array. So you have the advantages of a list (no ReDimming) and the access of an array.

Edited 4 Years Ago by Reverend Jim: n/a

This question has already been answered. Start a new discussion instead.