Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output .txt File Question 2

Status
Not open for further replies.

Palmyra

Programmer
Jan 5, 2007
150
US
I'm outputting a file to .txt for use by a label software package, which prints labels. I'm using the below code, which worked until we came across some data that wasn't consistent in length. (I'm creating equal distances between each piece of data). Is there a way to account for data of inconsistent length.

Open DestinationFolder & "SidetabLabels.txt" For Output As #1

Print #1, ""

Print #1, Me.txtfBarcode1 & " " & Me.txtMatter1 & " " & Me.txtFName1 & " " & Me.TextBox1 & " " & Me.TextBox2

Print #1, Me.txtfBarcode2 & " " & Me.txtMatter2 & " " & Me.txtFName2 & " " & Me.TextBox4 & " " & Me.TextBox5

Print #1, Me.txtfBarcode3 & " " & Me.txtMatter3 & " " & Me.txtFName3 & " " & Me.TextBox7 & " " & Me.TextBox8

Print #1, Me.txtfBarcode4 & " " & Me.txtMatter4 & " " & Me.txtFName4 & " " & Me.TextBox10 & " " & Me.TextBox11

Print #1, Me.txtfBarcode5 & " " & Me.txtMatter5 & " " & Me.txtFName5 & " " & Me.TextBox13 & " " & Me.TextBox14

Print #1, Me.txtfBarcode6 & " " & Me.txtMatter6 & " " & Me.txtFName6 & " " & Me.TextBox16 & " " & Me.TextBox17

Close #1
 


Hi,

Check out the Len function and the Left function for starters.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I'd use the Tab function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 



"some data that wasn't consistent in length."

Too LONG or too SHORT?

Too LONG: Use Len, Left.

Too SHORT: Use Tab function.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
The data in position one is sometimes shorter. I tried this with 'tab'. I also tried two tabs between each field.


Open DestinationFolder & "SidetabLabels.txt" For Output As #1

Print #1, ""


Print #1, Me.txtfBarcode1 & vbTab & Me.txtMatter1 & vbTab & Me.txtFName1 & vbTab & Me.TextBox1 & vbTab & Me.TextBox2

Print #1, Me.txtfBarcode2 & vbTab & Me.txtMatter2 & vbTab & Me.txtFName2 & vbTab & Me.TextBox4 & vbTab & Me.TextBox5

Print #1, Me.txtfBarcode3 & vbTab & Me.txtMatter3 & vbTab & Me.txtFName3 & vbTab & Me.TextBox7 & vbTab & Me.TextBox8

Print #1, Me.txtfBarcode4 & vbTab & Me.txtMatter4 & vbTab & Me.txtFName4 & vbTab & Me.TextBox10 & vbTab & Me.TextBox11

Print #1, Me.txtfBarcode5 & vbTab & Me.txtMatter5 & vbTab & Me.txtFName5 & vbTab & Me.TextBox13 & vbTab & Me.TextBox14

Print #1, Me.txtfBarcode6 & vbTab & Me.txtMatter6 & vbTab & Me.txtFName6 & vbTab & Me.TextBox16 & vbTab & Me.TextBox17


Close #1

but got below as an output file:


F8903 02269-00120 0099 001 001
000126328 02269-00120 0003 001 001
F8903 02269-00120 0099 001 001
000126328 02269-00120 0003 001 001


 
I didn't suggest the vbTab constant but the Tab [!]function[/!].

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

If you ALWAYS want to have, let's say 10, characters as your BarCode, you may do:
Code:
Print #1, [blue]Left$(Me.txtfBarcode1[/blue][red].Text[/red][blue] & Space(10), 10)[/blue] & vbTab & Me.txtMatter1[red].Text[/red] & vbTab & Me.txtFName1[red].Text[/red] & vbTab & Me.TextBox1[red].Text[/red] & vbTab & Me.TextBox2[red].Text[/red]

Have fun.

---- Andy
 
Actually, what would really be helpful is to start Me.txtfBarcode1.text in position 1; start me.txtMatter1.txt in position 11; start me.txtFName1.text in position 21, etc.

Thanks.
 
Print #1, Me.txtfBarcode1; Tab(11); Me.txtMatter1; Tab(21); Me.txtFName1; Tab(31); Me.TextBox1; Tab(41); Me.TextBox2

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you. I tried the tab function but then PHV's code, which worked perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top