2017-04-08 2 views
0

このコードでは、これらの宣言をListBoxに入れることができますが、残念ながら実行時には口座番号だけが表示され、それ以外は表示されません。私は何が間違っているのかを見出そうとしていますが、それを理解することはできません。ATM用の表示コードの作成

Dim Loan As Decimal 
Dim Account_Number, CustomerName, OpeningBalance, CurrentBalance, Loan_Taken, Amount_of_Loan, Amount_Deposited As String 

If OneAccount.LoanTaken Then 
    Loan = OneAccount.CustomerLoan 

    Account_Number = TextBox1.Text 
    CustomerName = TextBox2.Text 
    OpeningBalance = Val(TextBox3.Text) 
    CurrentBalance = Val(TextBox3.Text) - Val(TextBox5.Text) 
    Label8.Text = CurrentBalance 
    If CheckBox1.Checked = True Then 
     Loan_Taken = "Yes" 
    Else 
     Loan_Taken = "No" 
    End If 
    Amount_of_Loan = Format(Loan, "Currency") 
    Amount_Deposited = Label8.Text 
    Amount_Deposited = Amount_Deposited 
    Amount_Deposited = Format(Amount_Deposited, "Currency") 

    ListBox2.Items.Add(String.Format(Account_Number, CustomerName, OpeningBalance, CurrentBalance, Loan_Taken, Amount_of_Loan, Amount_Deposited)) 
End If 
+0

https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – Jens

答えて

1

問題はここに、このラインで

ListBox2.Items.Add(String.Format(Account_Number, CustomerName, OpeningBalance, CurrentBalance, Loan_Taken, Amount_of_Loan, Amount_Deposited)) 

あるString.Formatのためのドキュメントです:https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx

私はあなたがそれをフォーマットしようとしている正確かどうかはわかりませんけど、あなた単純に行うことができる

ListBox2.Items.Add(Account_Number + " " + CustomerName + " " + OpeningBalance + " " + CurrentBalance + " " + Loan_Taken + " " + Amount_of_Loan + " " + Amount_Deposited) 

これは、すべての項目をリストボックスにスペースを入れてb間。

0

アイテムをListBox2に追加する行を変更する必要があります。 String.Formatを次のようにString.Joinに変更します。

これは、間にスペースを入れてすべての値を結合します。

String.Formatの()それが最初の引数として文字列を取ると、以下のすべての引数は、このような最初の文字列に挿入されますので、動作しません:

String.Format("Name: {0}, Age: {1}", "John", 20) 
' "Name: John, Age: 20" 

だから、どちらかString.Concatです()またはString.Join()です。

String.Concat("Hello", "World", "!) ' "HelloWorld!" 
String.Join(", ", "0", "1", "2", "3") ' "0, 1, 2, 3" 
関連する問題