473,542 Members | 2,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

print data in txt file in tabular format

232 New Member
Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2. Dim sPath As String
  3. Function ITAX()
  4. sPath = "C:\temp\" ' just have the directory here
  5. Set rs = CurrentDb.OpenRecordset("SAL")
  6. Open sPath & "TAX.txt" For Output As #1
  7. Do Until rs.EOF
  8.     EName = rs("name")
  9.     Edesg = rs("desg")
  10.     ecode = rs("ecode")
  11.     Print #1, ecode & Space(5) & EName & Space(5) & Edesg
  12.     rs.MoveNext
  13. Loop
  14. Close #1
  15. rs.Close
  16. Set rs = Nothing
  17. End Function
this code displays same in below format which looks ugly.I want to display same in tabular format.such that name in one column designation in one columns in synchronization kindly advise how to print data in txt file in tabular format?
Expand|Select|Wrap|Line Numbers
  1. 0189    SMT BIMLA             HEAD ASSTT
  2. 0190    SH PARTAP SINGH BIST  HEAD ASSTT
  3. 018     SMT BIM               HEAD ASSTT
  4. 019     SH TAP SINGH BIST     HEAD ASSTT
Dec 12 '12 #1
4 2084
ADezii
8,834 Recognized Expert Expert
You can Output to Print Zones and pad the middle String Variable with a fixed number of Spaces that you define, as in:
Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2. Dim sPath As String
  3.  
  4. 'User Defined CONSTANT
  5. Const conLENGTH As Byte = 20
  6.  
  7. sPath = "C:\temp\" ' just have the directory here
  8. Set rs = CurrentDb.OpenRecordset("SAL")
  9.  
  10. Open sPath & "TAX.txt" For Output As #1
  11.  
  12. Do Until rs.EOF
  13.   EName = rs("name")
  14.   Edesg = rs("desg")
  15.   ecode = rs("ecode")
  16.     Print #1, Format$(ecode, "0000"), EName & Space$(conLENGTH - Len(EName)), Edesg
  17.       rs.MoveNext
  18. Loop
  19.  
  20. Close #1
  21.  
  22. rs.Close
  23. Set rs = Nothing
  24.  
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. 0189          SMT BIMLA                   HEAD ASSTT
  2. 0190          SH PARTAP SINGH BIST        HEAD ASSTT
  3. 0018          SMT BIM                     HEAD ASSTT
  4. 0000          SH TAP SINGH BIST           HEAD ASSTT
Dec 12 '12 #2
NeoPa
32,563 Recognized Expert Moderator MVP
While I have no doubt that ADezii's solution is perfectly correct and very useful, it may help to know that the Print# command, by default, tabulates your data for you anyway. You are simply bypassing this functionality by joining all your data into a single string before sending it.

If you use the comma (,) character to separate the values for each column it will tabulate automatically to the default column widths. If you want to tabulate to a specific column then this is also supported by using Tab(n) in your output stream, where n is the column number desired. You can also set the charpos for the next item to print and print a set number of spaces using Spc(n). Look in the help page for all this information.

Fundamentally though, Print# was designed to support these features.
Dec 12 '12 #3
ADezii
8,834 Recognized Expert Expert
Print #1, ecode, EName, Edesg
will produce:
Expand|Select|Wrap|Line Numbers
  1. 189          SMT BIMLA     HEAD ASSTT
  2. 190          SH PARTAP SINGH BIST        HEAD ASSTT
  3. 18           SMT BIM       HEAD ASSTT
  4. 0            SH TAP SINGH BIST           HEAD ASSTT
Print #1, ecode; Tab(10); EName; Tab(35); Edesg
although a little more confusing, will produce:
Expand|Select|Wrap|Line Numbers
  1. 189     SMT BIMLA                HEAD ASSTT
  2. 190     SH PARTAP SINGH BIST     HEAD ASSTT
  3. 18      SMT BIM                  HEAD ASSTT
  4. 0       SH TAP SINGH BIST        HEAD ASSTT
Dec 12 '12 #4
NeoPa
32,563 Recognized Expert Moderator MVP
Indeed. Clearly the second option is appropriate for this question, where the first isn't.

Although, with a limited length (<8 chars) number value at the start you could get away with :
Expand|Select|Wrap|Line Numbers
  1. Print #1, ecode, EName, Tab(35); Edesg
Only very variable fields need be handled by Tab(n).
Dec 12 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2710
by: Bob | last post by:
Hi, I am trying to use BULK INSERT with format file. All of our data has few bytes of header in the data file which I would like to skip before doing BULK INSERT. Is it possible to write format file to skip these few bytes of header before doing BULK INSERT? For example, I have a 1 GB data file with 1000 byte header. Except for first...
2
3526
by: Vanessa | last post by:
I need to read/extract data from an Excel file using ASP. However, the Excel file is not in regular tabular format; instead, it is actually a form. Therefore, it contains many checkbox and merged cells with data. I have followed this web page's instruction (http://www.haneng.com/Forums_Post.asp?id=4099) to read data out, but whenever the...
4
3642
by: Eric | last post by:
How to i create a form in tabular format without using wizard. thanks,
3
2172
by: lucky | last post by:
Hi guys, i want to write some data in tabular format in text file. i've data in strings and i want to write like this in file col1 col2 col3 d1 d1 d1 d2 d2 d2 d3 d3 d3
2
2378
by: teju | last post by:
Hello, I have to display all the data from the database in tables in ASP. I am able to get the data but the problem is of displaying one to many relations.Like below Title1 has two records but how would i display in the table Title1 heading1 heading 2 heading 3 x y x1 y1 a b a1 ...
2
3286
by: madhu542 | last post by:
Hi, I am trying to print the values of a file in the tabular format... The contents of the file are :- TILE 1: Serial Number: 1 Model Number: 110A Hardware Rev: 220A
1
2629
by: sharan | last post by:
Using the expat parser (http://expat.sourceforge.net/) i have to parse the following xml file and print it on the screen in tabular format. Want a c program on that in Linux environment. xml file is: <?xml version="1.0"?> <users> <user id="1"> <nameHari Oum </name> <age24 </age> <departmentProduct Development </department>
1
3090
by: sharan | last post by:
Using the expat parser (http://expat.sourceforge.net/) i have to parse the following xml file and print it on the screen in tabular format using C language. i am getting ouput serially but not in tabular xml file is: <?xml version="1.0"?> <users> <user id="1"> <nameHari Oum </name> <age24 </age>
4
6243
by: jeet123 | last post by:
hi, i am new to c#. How can i make a form which displays data in a tabular format where the data is retrieved from the database (ms-access) and displayed in that from in table. No matter if the table data is editable or not but yes, the user must be able to print that data. if we can add this feature of if the records displayed exceeds the...
1
2675
by: zwamin | last post by:
can someone let me know the html code for reading a text file with tab delimiter in a webpage in tabular format? number of rows in the text file is not known...
0
7395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7333
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7326
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7673
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3382
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1803
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
946
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
624
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.