Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

write 2 columns

Posted on 2009-04-11
5
Medium Priority
?
221 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

877 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