Solved

write 2 columns

Posted on 2009-04-11
5
215 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

766 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