• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

write 2 columns

I am writing to a txt file from vb.net.

I cant write 2 columns of data and have the 2nd col start at same place.
Col1 is OK but col2 starts at different places depending on how  big col1 ,row  data is.

How do i force this as currently i use tabs but again this doesnt work.


Private Sub write_file()
        w = File.AppendText(filename)
        eqNo += 1
        count += 1
    
        If count > 2 Then '2nd col
            w.WriteLine()
 
            count = 1
        End If
 
       
        w.Write(eqNo & ") " & eq1)
        w.Write(vbTab & vbTab & vbTab & vbTab)
 
  
        End If
        w.Close()
 
    End Sub

Open in new window

0
jagguy
Asked:
jagguy
  • 3
  • 2
1 Solution
 
rockiroadsCommented:
So  basically what you are after is a fixed length text file. Have you considered padding the string
0
 
jagguyAuthor Commented:
the first col has varied length from 10 to 25 chars so how do i pad this the 1st col is always say 30 chars?
0
 
rockiroadsCommented:
U can use the padRight method
eg

s2 = "Helllo There"

s2 = s2.PadRight(30, Convert.ToChar(" "))

PadRight returns the padded string, it does not update the string you used it on so you got to assign it to a variable. Same variable works (see above)

Syntax is PadRight(length, char)

so you can pad using any character u want

0
 
rockiroadsCommented:
there is also PadLeft if you want to left pad the string
0
 
jagguyAuthor Commented:
 strprint = eqNo & ") " & eq1
        strprint = strprint.PadRight(30)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now