Results 1 to 2 of 2

Thread: trouble with alignment in vb.net

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    4

    trouble with alignment in vb.net

    Ok here is what my question asks:

    A company has currently 6 sales staff (but we could have many more)that each sell to the east, west and central regions of canada. The data is in a text file called sales.txt in CSV format(use the split function shown in class to handle the CSV file). The fields(separated by commas) are salesperson name, sales in the east, west and central regions. Make up the file and save it along with your program. When the user clicks on a command button, input the file into 4 arrays called sname(), west sales(), centralsales() and eastsales() - you can assume that the number of employees can only rise up to 100. After that, a listbox shoudl be filled with a report in the format shown below. Note how the columns are right justified and also note that the totals are calculated and are not part of your text file.

    Ok I got the file and everything in the program working except for getting the values listed in the table to be right justified. Right now they are crooked. Does anyone know how to fix this? Here is my code.


    Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
    Me.Hide()
    End Sub

    Private Sub btngenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngenerate.Click
    Dim fmtstr As String = "{0,-20} {1, 13:C0} {2,13:C0} {3,13:C0} {4,13:C0}"
    Dim sname(100) As String
    Dim eastsales(100), westsales(100), centralsales(100) As Double
    Dim n, i As Integer
    Dim lin, fields(3) As String
    Dim sr As IO.StreamReader = IO.File.OpenText("sales.txt")
    Dim easttot, westtot, centraltot, tottot, rowtot As Double

    Do While sr.Peek <> -1
    lin = sr.ReadLine
    fields = lin.Split(",")

    sname(n) = fields(0)
    eastsales(n) = Val(fields(1))
    westsales(n) = Val(fields(2))
    centralsales(n) = Val(fields(3))

    n = n + 1
    Loop
    sr.Close()
    lstresult.Items.Add(Space(50) & "SALES REPORT")
    lstresult.Items.Add(String.Format(fmtstr, "", " EAST", "WEST", "CENTRAL", "TOTAL"))

    For i = 0 To n - 1
    rowtot = eastsales(i) + westsales(i) + centralsales(i)
    easttot = easttot + eastsales(i)
    westtot = westtot + westsales(i)
    centraltot = centraltot + centralsales(i)
    tottot = tottot + rowtot
    lstresult.Items.Add(String.Format(fmtstr, sname(i), eastsales(i), westsales(i), centralsales(i), rowtot))

    Next

    lstresult.Items.Add(String.Format(fmtstr, "", "", "", "", ""))
    lstresult.Items.Add(String.Format(fmtstr, "TOTALS", easttot, westtot, centraltot, tottot))

    End Sub

    Private Sub frmq2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    I've attached a jpg file of how it looks like right now crooked.
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width