这段代码写入使这些声明进入ListBox但不幸的是,当它运行时,它只显示帐号而不显示任何其他内容。我试图找出我做错了什么,但无法弄明白。
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 :(得分: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)
将所有项目添加到列表框中,中间有空格。
答案 1 :(得分:0)
您需要更改将项目添加到ListBox2的行。将String.Format更改为String.Join,如下所示:
String.Join(" ", Account_Number, CustomerName, OpeningBalance, CurrentBalance, Loan_Taken, Amount_of_Loan, Amount_Deposited)
这会将所有值与两者之间的空格连接在一起。
String.Format()不起作用,因为它将String作为第一个参数,所有后面的参数将插入到第一个字符串中,如下所示:
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"