【问题标题】:vbtab issue in a do until loop in vb.netvb.net 中的直到循环中的 vbtab 问题
【发布时间】:2016-11-06 19:11:29
【问题描述】:

大家好,我在使用 vbtab 的应用程序中遇到问题 谁能知道是什么问题

这是我的代码:

        txtshowpayments.Text = "Student's ID" & vbTab & "Student's Name" & vbTab & "Total Payment" & vbCrLf

    Class217FileReader = New StreamReader("class217.txt")
    PaymentsFileReader = New StreamReader("payments.txt")
    Do Until PaymentsFileReader.EndOfStream
        Do Until Class217FileReader.EndOfStream
            Dim aline As String = Class217FileReader.ReadLine
            Dim aline1 As String = PaymentsFileReader.ReadLine
            Dim fields() As String = aline.Split(","c)
            Dim fields1() As String = aline1.Split(","c)

            Dim StudentId As Integer = Convert.ToInt32(fields1(0))
            Dim studentId1 As Integer = Convert.ToInt32(fields(0))
            Dim StudentName As String = fields(1) & " " & fields(2)
            Dim totalpayment As Integer = Convert.ToInt32(fields1(1)) + Convert.ToInt32(fields1(2)) + Convert.ToInt32(fields1(3))

            If ShouldDisplay(StudentId, studentId1) Then
                txtshowpayments.Text &= StudentId & vbTab & StudentName & vbTab & String.Format("{0:C}", totalpayment) & vbCrLf
            End If
        Loop
    Loop

感谢您的帮助

【问题讨论】:

  • 应该告诉我们问题出在哪里。我你不喜欢“列”在 ListBox 中对齐的方式吗?
  • @plutonix 正如您在图像中看到的 vbtab 在第 2 行和第 4 行无法正常工作的付款列,这是问题
  • 列表框没有列;使用 DataGridView
  • 图片在哪里?你能提供网址吗?

标签: vb.net do-loops


【解决方案1】:

使用格式字符串

Dim formatString As String = "{0,-12}     {1,-14}     {2}" & vbCrLf

txtshowpayments.Text = String.Format(formatString, "Student's ID", "Student's Name", "Total Payment")
formatString = String.Replace("{2}", "{2:C}")

Class217FileReader = New StreamReader("class217.txt")
PaymentsFileReader = New StreamReader("payments.txt")
Do Until PaymentsFileReader.EndOfStream
    Do Until Class217FileReader.EndOfStream
        Dim aline As String = Class217FileReader.ReadLine
        Dim aline1 As String = PaymentsFileReader.ReadLine
        Dim fields() As String = aline.Split(","c)
        Dim fields1() As String = aline1.Split(","c)

        Dim StudentId As Integer = Convert.ToInt32(fields1(0))
        Dim studentId1 As Integer = Convert.ToInt32(fields(0))
        Dim StudentName As String = fields(1) & " " & fields(2)
        Dim totalpayment As Integer = Convert.ToInt32(fields1(1)) + Convert.ToInt32(fields1(2)) + Convert.ToInt32(fields1(3))

        If ShouldDisplay(StudentId, studentId1) Then
            txtshowpayments.Text &= String.Format(formatString, StudentId, StudentName, totalpayment)
        End If
    Loop
Loop

更好...查看 DataGrid 控件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 2018-04-13
    相关资源
    最近更新 更多