2017-04-08 14 views
0

這段代碼編寫使得這些聲明進入列表框,但不幸的是,當它運行時,它只顯示帳號而不顯示其他內容。我試圖找出我做錯了什麼,但無法弄清楚。創建一個自動櫃員機的顯示代碼

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.Join(" ", Account_Number, CustomerName, OpeningBalance, CurrentBalance, Loan_Taken, Amount_of_Loan, Amount_Deposited) 

這將在之間的空間中所有的價值觀結合在一起。

的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" 
相關問題