以前の質問と同じプログラムに取り組んでいますが、現在修正されたプログラムの出力を調整するのに問題があります。一部がめちゃくちゃに見えるかもしれませんが、どういうわけか動作するようになりました。
いずれにせよ、出力は見出しと一致せず、見栄えがよくありません。これを修正する方法がわかりません。
Imports System.IO
Imports System.Convert
Public Class frmAll
'Declare Streamreader
Private objReader As StreamReader
'Declare arrays to hold the information
Private strNumber(24) As String
Private strName(24) As String
Private strSize(24) As String
Private decCost(24) As Integer
Private Sub frmAll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Set objReader
objReader = New StreamReader("products.csv")
Call FillArray()
End Sub
Private Sub FillArray()
'Declare variables and arrays
Dim decCost(24, 1) As Decimal
Dim strFields() As String
Dim strRec As String
Dim intCount As Integer = 0
Dim chrdelim As Char = ToChar(",")
'Set strRec to read the lines
strRec = objReader.ReadLine
'Do while loop to fill array.
Do While strRec <> Nothing
strFields = strRec.Split(chrdelim)
strNumber(intCount) = strFields(0)
strName(intCount) = strFields(1)
strSize(intCount) = strFields(2)
decCost(intCount, 0) = ToDecimal(strFields(3))
decCost(intCount, 1) = ToDecimal(strFields(4))
'Set strRec to read the lines again
strRec = objReader.ReadLine
'increment the index
intCount += 1
Loop
Call Calculate(decCost)
End Sub
Private Sub Calculate(ByVal numIn(,) As Decimal)
'Define arrays to hold total cost
Dim decRowTotal(24) As Decimal
'Define variables to hold the counters for rows and columns
Dim intR As Integer
Dim intC As Integer
'Calcualte total cost
For intC = 0 To 1
For intR = 0 To 24
decRowTotal(intR) += numIn(intR, intC) * 1
Next
Next
Call Output(numIn, decRowTotal)
End Sub
Private Sub Output(ByVal NumIn(,) As Decimal, ByVal RowTotalIn() As Decimal)
Dim strOut As String
Dim intR As Integer = 0
Dim intC As Integer = 0
strOut = "ID" & vbTab & "Item" & vbTab & vbTab & vbTab & "Size" & vbTab & vbTab & vbTab & vbTab & "Total Price" &
vbCrLf & "--------------------------------------------------------------------------------------------------------------------------------------------------" &
vbCrLf
For intC = 0 To 24
strOut &= strNumber(intC) & vbTab
strOut &= strName(intC) & vbTab
strOut &= strSize(intC) & vbTab & vbTab
strOut &= RowTotalIn(intC).ToString("c")
strOut &= vbCrLf
Next
rtbAll.Text = strOut
End Sub
End Class