Solved

write 2 columns

Posted on 2009-04-11
5
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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