2017-04-08 65 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" 
相关问题