• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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