我相信一切正常但我无法获得显示计算数据的标签,不知道我在哪里搞砸了。任何帮助将非常感谢。
Imports System.IO
Public Class Form1
Dim decMakeWithdrawal As Decimal
Dim decBalace As Decimal
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Close the form
Me.Close()
End Sub
Private Sub btnDeposit_Click(sender As Object, e As EventArgs) Handles btnDeposit.Click
Dim decMakeDeposit As Decimal
'Add Deposit
decMakeDeposit = CDec(InputBox("Please enter deposit if you have any"))
End Sub
Public Sub btnWithdraw_Click(sender As Object, e As EventArgs) Handles btnWithdraw.Click
Dim decBalance As Decimal
decMakeWithdrawal = CDec(InputBox("Please enter an amount to withdraw"))
If decBalance <= 0 Then
MessageBox.Show("Insufficient funds")
End If
End Sub
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim decIntRate As Decimal
decIntRate = CDec(InputBox("Please enter the interest rate:"))
End Sub
Private Function decintTrans() As Object
Throw New NotImplementedException
End Function
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim decInterTrans As Decimal
Dim decInterest As Decimal
decInterest = CDec(decintTrans())
decInterTrans += 1D
End Sub
End Class
Public Class Transaction
'Create member variables for properties
Public decBalance As Decimal
Private decIntRate As Decimal
Private decInterest As Decimal
Private intTrans As Integer
Private decMakeWithdrawal As Decimal
Private decMakeDeposit As Decimal
Private decInterestEarned As Decimal
'Create property procedures
Public Property Balance As Decimal
Get
Return decBalance
End Get
Set(value As Decimal)
decBalance = value
End Set
End Property
Public Property IntRate As Double
Get
Return decIntRate
End Get
Set(value As Double)
decIntRate = CDec(value)
End Set
End Property
Public Property InterestTotal As Double
Get
Return decInterest
End Get
Set(value As Double)
decInterest = CDec(value)
End Set
End Property
'calculate the amount of interest for the current period
'stores this value in the Interest property, and adds it to the Balance property
Public Sub addInterest(ByVal addInterest As Integer)
decInterestEarned = decBalance * (decIntRate / 12)
End Sub
'add deposit
Public Sub addDeposit(ByVal addDeposit As Decimal)
decMakeDeposit += addDeposit
End Sub
'withdraw
Public Sub subtractWithdrawl(ByVal subtractWithdrawal As Double)
If decMakeWithdrawal >= subtractWith() Then
decMakeWithdrawal = CDec(decMakeWithdrawal - subtractWith())
Else
MessageBox.Show("No sufficient balance")
End If
End Sub
Private Function subtractWith() As Double
Throw New NotImplementedException
End Function
End Class
答案 0 :(得分:0)
我认为您的代码因您添加的目前正在使用的内容而变得复杂。
所以简单来说,我已经删除了额外的东西并纠正了我能看到的任何错误。仍然需要进行大量调整,并且像成员blackwood一样,您应该在处理数据之前验证用户输入的值。
然而,只是为了让你开始并让你走上正确的道路,尝试下面的代码,不要忘记将它与你原来的代码进行比较,以便你可以看到你出错的地方。
祝你好运Option Explicit
Imports System.IO
Public Class Form1
Dim MyTransactor as Transaction
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim decIntRate As Decimal
MyTransactor = New Transaction()
decIntRate = CDec(InputBox("Please enter the interest rate:"))
MyTransactor.IntRate = decintRate
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Close the form
Me.Close()
End Sub
Private Sub btnDeposit_Click(sender As Object, e As EventArgs) Handles btnDeposit.Click
Dim decMakeDeposit As Decimal
decMakeDeposit = CDec(InputBox("Please enter deposit if you have any"))
MyTransactor.addDeposit = decMakeDeposit
End Sub
Public Sub btnWithdraw_Click(sender As Object, e As EventArgs) Handles btnWithdraw.Click
decMakeWithdrawal = CDec(InputBox("Please enter an amount to withdraw"))
MyTransactor.subtractWithdrawl = decMakeWithdrawal
End Sub
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
MyTransactorAddInterest
MessageBox.Show(MyTransactor.InterestEarned & "Interest add to balance. Total balance now is " & MyTranasactor.Balance)
End Sub
End Class
Public Class Transaction
'Create member variables for properties
Public decBalance As Decimal
Private decIntRate As Decimal
Private decInterestEarned As Decimal
'Create property procedures
Public Property Balance As Decimal
Get
Return decBalance
End Get
Set(value As Decimal)
decBalance = value
End Set
End Property
Public Property IntRate As Double
Get
Return decIntRate
End Get
Set(value As Double)
decIntRate = CDec(value)
End Set
End Property
Public Property InterestEarned As Double
Get
Return decInterestEarned
End Get
Set(value As Double)
decInterestEarned = CDec(value)
End Set
End Property
'calculate the amount of interest for the current period
'stores this value in the Interest property, and adds it to the Balance property
Public Sub AddInterest()
decInterestEarned = decBalance * (decIntRate / 12)
decBalance =+ decInterestEarned
End Sub
'add deposit
Public Sub addDeposit(ByVal DepositValue As Decimal)
decBalance=+ DepositValue
End Sub
'withdraw
Public Sub subtractWithdrawl(ByVal WithdrawalValue As Double)
If decBalance >= WithdrawalValue Then
decBalance =- WithdrawalValue
Else
MessageBox.Show("No sufficient balance")
End If
End Sub
End Class