2017-02-15 17 views
0

ここでは、銀行口座の借方とクレジットを金額ごとに記入することができます。ユーザーは、すべての取引とその残高を照会することもできます。私はクレジットからの借方を差し引く式を作成するだけでなく、すべての取引を表示するのに問題があります。私がこれまで何時間も拘束されてきたので、これまでのことがここにあります。テキストボックスから複数のユーザー入力を保存し、テキストボックスから複数の値を追加しますか?

Public Class Form1 
    Dim valueDebit As Decimal 
    Dim valueCredit As Decimal 
    Dim total As Decimal 



    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     Me.Text = "Mike Smith's Bank Account" 
     Lb1.Visible = False 
     Lb2.Visible = False 
     Lb3.Visible = False 
     Tb1.Visible = False 
     Tb2.Visible = False 
     Bt1.Visible = False 
    End Sub 

    Private Sub Cb1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Cb1.SelectedIndexChanged 
     If Tb1.Text = "" Then 
      Tb1.Text = "0.00" 

     ElseIf Cb1.Text = "Credit" Then 
      Lb1.Visible = True 
      Lb2.Visible = True 
      Lb3.Visible = False 
      Tb1.Visible = True 
      Tb2.Visible = True 
      Lb1.Text = "Enter Credit Amount" 
      Lb2.Text = "Describe the Income" 
      Bt1.Visible = True 

      valueCredit = Convert.ToDecimal(Tb1.Text) 



     ElseIf Cb1.Text = "Debit" Then 
      Lb1.Visible = True 
      Lb2.Visible = True 
      Lb3.Visible = False 
      Tb1.Visible = True 
      Tb2.Visible = True 
      Lb1.Text = "Enter Debit Amount" 
      Lb2.Text = "Describe the Expense" 
      Bt1.Visible = True 

      valueDebit = Convert.ToDecimal(Tb1.Text) 


     ElseIf Cb1.Text = "Display Transactions" Then 
      Lb1.Visible = False 
      Lb2.Visible = False 
      Lb3.Visible = True 
      Tb1.Visible = False 
      Tb2.Visible = False 
      Bt1.Visible = False 


     ElseIf Cb1.Text = "Display Balance" Then 
      Lb1.Visible = False 
      Lb2.Visible = False 
      Lb3.Visible = True 
      Tb1.Visible = False 
      Tb2.Visible = False 
      Lb3.Text = "$" 

     End If 
    End Sub 

    Private Sub Bt1_Click(sender As Object, e As EventArgs) Handles Bt1.Click 
     Cb1.Text = "" 
     Tb1.Visible = False 
     Tb2.Visible = False 
     Lb1.Visible = False 
     Lb2.Visible = False 
     Tb1.Text = "" 
     Tb2.Text = "" 

    End Sub 
End Class 

助けてください。

答えて

0

最初に、借方は収入であり、クレジットは銀行口座の経費です。 第2に、この状況では提出型Buttonが理想的だと思います。

私が試した1つのオプション:public Class Transactionを作成し、フォームのList(Transaction)リストとトランザクションリストボックスを使用します。また、トランザクションを「提出する」ボタンを使用します。ループを使用してトランザクションのリストを取得し、合計金額/残高を取得することができます。

Public Class Form1 
    'Mod-level variable 
    Dim TransactionsList As New List(Of Transaction)  

    'Not exactly sure what all the labels are and the exact layout of your form, 
    'so you can apply this to your code 
    Private Sub Cb1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Cb1.SelectedIndexChanged 
    If Tb1.Text = "" Then 
     Tb1.Text = "0.00" 

    ElseIf Cb1.Text = "Credit" Then 
     Lb1.Visible = True 
     Lb2.Visible = True 
     Lb3.Visible = False 
     Tb1.Visible = True 
     Tb2.Visible = True 
     Lb1.Text = "Enter Credit Amount" 
     Lb2.Text = "Describe the Income" 
     Bt1.Visible = True 

     'valueCredit = Convert.ToDecimal(Tb1.Text) (Handled in buttonClick event) 

    ElseIf Cb1.Text = "Debit" Then 
     Lb1.Visible = True 
     Lb2.Visible = True 
     Lb3.Visible = False 
     Tb1.Visible = True 
     Tb2.Visible = True 
     Lb1.Text = "Enter Debit Amount" 
     Lb2.Text = "Describe the Expense" 
     Bt1.Visible = True 

     'valueDebit = Convert.ToDecimal(Tb1.Text) (Handled in buttonClick event) 

    ElseIf Cb1.Text = "Display Transactions" Then 
     Lb1.Visible = False 
     Lb2.Visible = False 
     Lb3.Visible = True 
     Tb1.Visible = False 
     Tb2.Visible = False 
     Bt1.Visible = False 

     'This is where you loop through list to get your transactions 
     For Each transaction In TransactionList 
      'Add each Transaction to the ListBox. Display the data however you like... 
      TransactionsListBox.Items.Add(
        String.Format("{0}: {1:C}. {2}", 
           transaction.Type, 
           transaction.Amount, 
           transaction.Description)) 
     Next  

    ElseIf Cb1.Text = "Display Balance" Then 
     Lb1.Visible = False 
     Lb2.Visible = False 
     Lb3.Visible = True 
     Tb1.Visible = False 
     Tb2.Visible = False 
     Lb3.Text = "$" 

    End If 
    End Sub  

    'Click button to submit the transaction.. 
    'Also easier for data validation, error catching, etc. 
    Private Sub SubmitTransactionButton_Click(sender As Object, e As EventArgs) Handles SubmitTransactionButton.Click 
     Dim transactionTypeString As String = Cb1.Text 
     Dim transactionDescriptionstring As String = Tb2.Text 
     Dim transactionAmountDecimal As Decimal 

     'If user enters non-numeric value, exception gets thrown 
     Try 
      'Convert amount to Decimal 
      transactionAmountDecimal = Decimal.Parse(Tb1.Text)   

      'Add to the list of Transactions 
      TransactionList.Add(New Transaction( 
          transactionTypeString, 
          transactionAmountDecimal, 
          transactionDescriptionstring)) 

     Catch FormatExceptionParameter as FormatException 
      transactionAmountDecimal = 0D 

     End Try 


    End Sub 

End Class 


Public Class Transaction 
    Public Sub New(type As String, amount As Decimal, description As String) 
     Me.Type = type 
     Me.Amount = amount 
     Me.Description = description  

     'Optional depending on how you want to enter data 
     'Ex. Enters 500 as a Credit (should be -500 to balance) (500 * -1 = -500)    
     If Me.Type = "Credit" Then 
      Me.Amount *= -1 
     End If 

    End Sub 

    Public Property Type As String 
    Public Property Amount As Decimal 
    Public Property Description As String 

End Class 

そして、計算のための上記を使用して...他の表示バランスで

'Create Calculate function 
Public Function CalculateBalance() As Decimal 
     Dim balanceDecimal As Decimal 

     'Looping through TransactionsList again to get each Amount, 
     'this time to calculate total Balance 
     For Each transaction In TransactionList 
      balanceDecimal += transaction.Amount 

     Next 

     Return balanceDecimal 

End Function 

コール/ IFブロック

ElseIf Cb1.Text = "Display Balance" Then 
      Lb1.Visible = False 
      Lb2.Visible = False 
      Lb3.Visible = True 
      Tb1.Visible = False 
      Tb2.Visible = False 
      Lb3.Text = "$" 

      'Whatever control you want to display the balance in 
      Tb1.Text = CalculateBalance().ToString("C2") 

    End If 

あなたが使用できる可能性の高い多くのソリューションがありますが、とこれはあなたが多分他のアイデアを手に入れることができるかもしれないことの一つです。私はあなたが何をしようとしているのかを助けてくれることを願っています。

関連する問題