Results 1 to 2 of 2

Thread: [RESOLVED] Help - read/write data from another class

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    22

    Resolved [RESOLVED] Help - read/write data from another class

    Hello,

    I'm a beginner in programming, a total newbie. I have searched (this forum) and others, with no luck. I'm sure the answer is already out there, but I have been unable to connect the dots.

    I'm looking for help with an assignement, that is probably 80% done. I'm not looking for someone to write it for me, but to help guide me with what I've done wrong and possibly how to fix it.

    My assignement is to create a simplistic checkbook organizer. The GUI is built, and the form is needing to call to a transactional class i have created. My problem is I dont know the right commands or syntax. I though I had it, but i'm getting an error.

    Error: "Arguement not specified for parameter 'PreviousBalance' of 'Public Sub New (PreviousBalance as Double)'.

    Here is my code so far for the form:
    Code:
    Private Sub btnAddTransaction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTransaction.Click
    
            'declare user input variables in this GroupBox2
            Dim TransactionAmount As Double
            Dim MyAmount As New transaction()
            MyAmount.Amount = TransactionAmount
    
            'Error Handling segment.  Try/Catch to look for invalid input.
            Try
                TransactionAmount = txtTransactionAmount.Text
    
            Catch ex As Exception
                MsgBox(ex.Message)
    
            End Try
    Here is my code for the transactional class:
    Code:
    Public Class transaction
        'private members
        Private _Amount As Double
        Private _CurrentBalance As Double
    
        'public members
        Public Sub New(ByVal PreviousBalance As Double)
            _Amount = 0.0
            _CurrentBalance = PreviousBalance
        End Sub
    
        'gets and sets the amount of starting balance
        Public Property Amount() As Double
            Get
                Return _Amount
            End Get
            Set(ByVal value As Double)
                _Amount = value
            End Set
        End Property
    
        ' gets and sets current balance
        Public ReadOnly Property CurrentBalance() As Double
            Get
                Return _CurrentBalance
            End Get
    
        End Property
    
        ' runs calculation on current balance + transaction amount
        Public Sub ComputeCurrentBalance()
            _CurrentBalance = _CurrentBalance + _Amount
        End Sub
    End Class
    Any help is appreciated. Thanks in advance!

  2. #2
    Addicted Member
    Join Date
    Jan 2012
    Location
    Athens, Greece
    Posts
    143

    Re: Help - read/write data from another class

    You should specify PreviousBalance when you create MyAmount. Your constructor needs tis parameter.

    You can even add the default constructior in your class

    Code:
        
    Public Sub New()
        _Amount = 0.0
        _CurrentBalance = 0.0
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width