Link to home
Start Free TrialLog in
Avatar of mad3654
mad3654

asked on

Print Columns

I need simple code to access a delimited text file on "A:" Drive and print the contents in 5 columns.  Need to display with no delimiter characters.

Sample of Data:
"B105","LOFTIS BALL","300 BOHLING LANE", 8223.30, 7.70
Avatar of Ruchi
Ruchi

Try something like this...

Private Sub Command1_Click()
    Open "A:\test.txt" For Output As #1
    Print #1, "B105", "LOFTIS BALL", "300 BOHLING LANE", 8223.3, 7.7
    Close #1
End Sub
Private Sub Command1_Click()
    Dim fn As Integer
    Dim s As String
    Dim v As Variant
    fn = FreeFile()
    Open Text1 For Input As fn
    While Not EOF(fn)
        Line Input #fn, s
        v = Split(s, ",")
        Printer.Print Join(v, vbTab)
    Wend
    Close fn
End Sub
Or, you can write

Private Sub Command1_Click()
    Open "A:\test.txt" For Output As #1
    Print #1, Tab(10); "B105";
    Print #1, Tab(25); "LOFTIS BALL";
    Print #1, Tab(40); "300 BOHLING LANE";
    Print #1, Tab(55); 8223.3;
    PRint #1, Tab(70); 7.7
    Close #1
End Sub



Tab - to move to the specified column in the line so the next value can be ..output to start at that column position.

Print# - to write data to the specified any text, data file.

Write# - to add delimiters and separators
Avatar of mad3654

ASKER

I need code to access a delimited text file on "A:" Drive and print the contents in 5 columns.  Need to display with no delimiter characters.


I need something more like

Open "A:VB5.dat" for input as #1
Do While not EOF(1)

 "I am not sure what goes here something like- Line input #1, ID, Pname, Address, Due, Bal"?

Print ID, Pname, Address, format _(Due, "currency"), format(Bal, currency)
loop

end sub

I am opening a Data file named VB5.dat
Sample of data:

"B105","LOFTIS BALL","300 BOHLING_ LANE", 8223.30, 7.70
ASKER CERTIFIED SOLUTION
Avatar of Ruchi
Ruchi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I meant "c:\text.txt" to "A:\test.txt"