title: Using IF statements to find string length in array for alignment (Visual Basic)
body: <p>My question is just as it says in the title. How would one use IF statements to find the string-length of content in an array, and then make it so that they show up in a Rich Text Box with the left sides aligned?</p>
  
  <p>Noting that one value in my array is a Decimal.</p>
  
  <pre><code>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 the FillArray sub to fill the array
          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 &lt;&gt; 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 the Calculate sub for calculation
          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 the Output sub to configure the output.
          Call Output(numIn, decRowTotal)
  
      End Sub
  
      Private Sub Output(ByVal NumIn(,) As Decimal, _
                         ByVal RowTotalIn() As Decimal)
          'Variables
          Dim strOut As String
  
          Dim intR As Integer = 0
          Dim intC As Integer = 0
          'Set header for output.
          strOut = "ID" &amp; vbTab &amp; "Item" &amp; vbTab &amp; vbTab &amp; vbTab &amp; "Size" &amp; _
              vbTab &amp; vbTab &amp; vbTab &amp; vbTab &amp; "Total Price" &amp; _
              vbCrLf &amp; "---------- ... -------------------------" &amp; vbCrLf
  
          'For loop to add each line to strOut, setting
          'the RowTotalIn to currency.
          For intC = 0 To 24
              strOut &amp;= strNumber(intC) &amp; vbTab
              strOut &amp;= strName(intC) &amp; vbTab
              strOut &amp;= strSize(intC) &amp; vbTab
              strOut &amp;= RowTotalIn(intC).ToString("c") &amp; vbCrLf
          Next
          'Add strOut to rbtAll
          rtbAll.Text = strOut
      End Sub
  End Class
  </code></pre>
  
  <p>Output:</p>
  
  <blockquote>
    <p>P0001  Coffee - Colombian Supreme 24/Case: Pre-Ground 1.75 Oz
    Bags  $16.50</p>
    
    <p>P0002 Coffee - Hazelnut   24/Case: Pre-Ground 1.75 Oz Bags    $24.00</p>
    
    <p>P0003 Coffee - Mild Blend 24/Case: Pre-Ground 1.75 Oz Bags    $20.50</p>
    
    <p>P0004 Coffee - Assorted Flavors   18/Case. Pre-Ground 1.75 Oz
    Bags  $23.50</p>
    
    <p>P0005 Coffee - Decaf  24/Case: Pre-Ground 1.75 Oz Bags    $20.50</p>
  </blockquote>
  
  <p>It shows up with vbTabs in my output, but still, it looks similar in that they are not aligned. The first two do, but after that they are not, and I am totally lost.</p>