Visual Basic .Net Objects and Classes

时间:2015-04-29 00:20:05

标签: .net class object basic

I am designing an very high level high ATM. I know i can use databases but would like to further explore the little I know of objects.

I have the ATM running on windows forms. I want the form to print some for example the account balance that will stored in a person object inside an account class.

Public Class Account

                Public Shared _PersonName As String
                Public Shared _WithBank As String
                Public Shared _AccountNumber As Double
                Public Shared _AccountBalance As Double
                Public Shared _PIN As Integer

        Public Sub New(ByVal personName As String, ByVal accountNumber As Double, ByVal accountBalance As Double, ByVal pin As Integer)
                _PersonName = personName
                _AccountNumber = accountNumber
                _MaxWithdrawal = Withdrawal()
                _AccountBalance = accountBalance
                _PIN = pin
            End Sub
End Class

In the forms themselves i would like to be able to switch between two persons based on the input pin number. I would like to be able to say Account.NewPerson.accountNumber and be able to retrieve the accountNumber of person whose pin number was entered.

I am struggling now creating the objects. I may be doing this all wrong and would appreciate any constructive guidance. I am unsure where to put these. in the same class or in a new class?

Public Shared Person1 As Account = New Account("Tom Jones", 123456789, 6000, 1234)
Public Shared Person2 As Account = New Account("Bob Marley", 987654321, 500, 5678)
Public Shared NewPerson As Account = New Account("", 0, 0, 0)

In the forms i have an if statement that if else statement. if result1 then Account.NewPerson = Account.Person1. if result2 then Account.NewPerson = Account.Person2.

I think this is the right way to go but i could be entirely on the wrong tracks. If this is solved, i will swap out the if else statement for a search as I know how to do that.

Thanks for your help

1 个答案:

答案 0 :(得分:0)

将您的帐户对象保存在通用列表中。

Dim Accounts As List(Of Account) = New List(Of Account) 
Accounts.Add(New Account("Tom Jones", 123456789, 6000, 1234) )  
Accounts.Add(New Account("Bob Marley", 987654321, 500, 5678) )
Dim currentName = Accounts(0)._PersonName

您还可以将列表绑定到表单中的组合框,并根据选择的帐户更改视图。