Solved

write 2 columns

Posted on 2009-04-11
5
216 Views
Last Modified: 2013-12-17
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
Comment
Question by:jagguy
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24121633
So  basically what you are after is a fixed length text file. Have you considered padding the string
0
 

Author Comment

by:jagguy
ID: 24121653
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 24121686
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
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24121689
there is also PadLeft if you want to left pad the string
0
 

Author Comment

by:jagguy
ID: 24121690
 strprint = eqNo & ") " & eq1
        strprint = strprint.PadRight(30)
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question