ACCESS THE ACCOUNT OBJECT TO DISPLAY A LIST OF TRANSACTIONS

I have two classes, transactions and account.
In transaction class, I have declared a number of private variable ( t_id As Integer, name As String, t_amount As Double, t_date As String, t_mode As Boolean, t_type As String, t_BegBal As Double, t_EndBal As Double).

In account class, u have two instances of transaction class named Checking and Savings, Private totalBal As Integer, and a sub displayTransactions procedure (shown as follows).

I have a question on how to make an account object to display a list of transaction in a list box. My prof hinted to me that the method might be declared with Sub displayTransactions(By Val lstbox as ListBox).

Sub displayTransactions(ByVal lstBox As ListBox, ByVal lastTrans As Integer)
Dim fmtstr As String = "{0,-10}{1,-20}{2,-8}{3,-8}{4,15}{5,-8}{6,15}"
Dim count As Integer
lb.Items.Clear()
'loop over all avaliable elements of the accts array
For count = 0 To lastTrans
//lb.Items.Add(String.Format(fmtstr)
//NEED TO DISPLAY AN ACCOUNT OBJECT, WHICH WILL DISPLAY A LIST OF TRANSACTIONS
Next
End Sub

//below is part of my code for loading data from access into account object
Do While oDR.Read()
If (oDR.Item("type") = "checking") Then
'checking transaction
With accts(count).checking
.id = oDR.Item("trans_ID")
.Name = oDR.Item("name")
.Amount = oDR.Item("amount")
.tDate = oDR.Item("date")
.Mode = oDR.Item("mode")
.BegBal = oDR.Item("beg_CBal")
.EndBal = oDR.Item("end_CBal")
End With
Else
'savings transaction
With accts(count).savings
.id = oDR.Item("trans_ID")
.Name = oDR.Item("name")
.Amount = oDR.Item("amount")
.tDate = oDR.Item("date")
.Mode = oDR.Item("mode")
.BegBal = oDR.Item("beg_SBal")
.EndBal = oDR.Item("end_SBal")
End With
End If

count = +count
Loop

I HAVE A HARD TIME IN FIGURING OUT HOW TO ACCESS THE ACCOUNT OBJECT TO DISPLAY A LIST OF TRANSACTIONS. APPRECIATED IF GUIDANCE IS GIVEN. THANKS

Comments

  • I am not sure if you mistyped or maybe I misunderstand. I think you should have two instances of the Account class object and not two instances of the Transaction class object. These instances should be declared something like...

    dim oSavings as Account = new Account()
    dim oChecking as Account = new Account()

    I would have the Account class hold a collection of Transaction class objects. This more closely resembles the natural relationship that exists here.
    I would then do something more like...

    Do While oDR.Read()
    ...If oDR.Item("Type") = "checking" Then
    ......oChecking.LoadTransaction(oDR)
    ...Else
    ......oSavings.LoadTransaction(oDR)
    ...End If
    Loop

    This would require the Account class to have a method named "LoadTransaction" that would accept a DataReader and put it in the collection. It would probably be better to write the proc as...

    Public Sub LoadTransaction(ByVal id as ???,
    ...........................ByVal Name as String,
    ...........................ByVal Amount as Double,
    ...........................ByVal Date as Date,
    ...........................ByVal Mode as ????,
    ...........................ByVal BegBal as Double,
    ...........................ByVal EndBal as Double)
    ...Dim oTemp as Transaction
    ...oTemp = New Transaction(id, Name, Amount, _
    ...........................Date, Mode, BegBal, EndBal)
    ...me.Transactions.Add(oTemp)
    End Sub

    This will require that the Transaction class contains a constructor that accepts the parameters as above (or rather as however you decide to do it). Me.Transactions will need to resolve to a collection that has an add method that will accept a transaction object.

    In the end, not only is this easier to work with, but you can simply use a line like the following to add your transactions to a listbox...

    lb.DataSource = oSavings.Transactions

    If you absolutely must loop the Transactions, just go...

    for each x in oSavings.Transactions
    ...lb.items.add(x)
    Next

    I did this rather quickly, and I assume you were fishing for ideas, not cut and paste code, so please excuse me if this code requires further "polishing." The design concepts are what is important. Hopefully this helps...

    -Ray


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion