Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Creating ASCII file

Posted on 2004-09-13
Medium Priority
Last Modified: 2012-06-27
Dear Friend ,

I have developed programme using VB 6.0 . There I have used MS Access 97 for data base . Time to time user will add data to the data base . After adding data to the data base I want to automatically create ASCII file . But I don't no to do this . If some body can help me to create ASCII file . Please guide me . It is good if I can create ASCII file after adding new data to the database. But All the record should be included to the ASCII file .

Please write to me ASAP .

Question by:PChandima
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
  • 4
  • 3
  • 2
  • +3

Expert Comment

ID: 12052314

Explain your ASCII file please. what do u want to save in it? how?


Author Comment

ID: 12052407
I have MS Access 97 database . There I want to convert one table to ASCII file . This should I want to be done using VB . That mean if I click Command Button , that database tabe should be saved as a ASCII file . This one I want to do time to time .

Thanks .

LVL 59

Expert Comment

by:Julian Hansen
ID: 12053161
An ASCII File simply means that the data is saved in readable text. It does not however, say what the format of that text is i.e. is it comma seperated variables, fixed length records etc.

There is information you need to tell us before we can assist you. When you want data written to the file - must it append to an existing file, create a new file, overwrite a record if it exists etc.

Explain to us what you want to do with the ASCII file and that will also help.

Basically you have not given us enough information to help you properly.

For some information on accessing text files from Visual Basic go here
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 12054154
My friend
I think I understand what you want to do. In order to accomplish what you want you have to write some VBA code.
Add a command button to the form where you enter the data and in the event tab of that button, click on Code Builder.
in the VBA window that appears you have to write code that goes through the records one by one, you open an ASCII file for writing and you start dumping the contents of the records one by one to the file. You must close the file when done.

if you used the same file name the old file will be erased every time. If this is what you want, fine. If you want to keep the old files, you may prompt the user for a new file name and use the name that he supplies.

For help in VBA visit:


Expert Comment

ID: 12057816
    Perhaps these may help.

Export an ADO Recordset to a Text File

Class to Export Database Tables to Text File


Author Comment

ID: 12061890
Dear All Friends,

We will forget the database part. Help me to up data text file . Here I will give more details . What I want is this . I have VB 6 Programme . In one form I have included lot of text boxes , labels, MSFlex grid control , etc. There user will enter data to the text box and as well as some date will be display on the MSFlex grid control. I want to add this data to the text file . But text file can't be replaced. New data should be add to the data base . Acctualy it is like database file . Only differance is that one is text file . Please help me to write coding for this .


Expert Comment

ID: 12062165
You are confusing everybody here. Now you are saying that the file is the database. You still can use ADO to access the text file and leave it up to ADO to handle the file.

You have to make up your mind. We are here to help you but you have to be clear on what you want.

LVL 59

Expert Comment

by:Julian Hansen
ID: 12062230

I echo the sentiments of Bestdev. If you cannot explain what it is you want we can't help you.

If you want to write the data to a text file then you can refer to the URL I mentioned above

This will give you some pointers on writing data directly to a text file.

What do you need the text file for? This is important because data can be represented in many different ways in a text file

* Delimited - comma, tab etc (with in this you need to be careful because you need a way of handling data that contains delimiters and other data such as dates and strings with spaces etc.)
* Fixed length (Easier than delimited in some ways but can result in a much bigger file than is necessary)

Explain to us what you want to use the text file for and it will help in finding a solution.

Expert Comment

ID: 12062474
Here's how to do it. Save the contents of your textboxes to a string and append it to a file everytime you save.

Try the following code
This code opens the file mydata.txt for appending. If the file does not exist it creates it and appends the contents of your textboxes to the file.  Just drop this code in your cmdSave_Click event

    Dim filesystem As Object
    Dim txtstream As Object
    Dim strRecord as String

    strRecord = txtName.text & "," txtAge.text & "," & txtAddress.text

    Set filesystem = CreateObject("Scripting.FileSystemObject")
    Set txtstream = filesystem.openTextFile("c:\mydata.txt", 8, True)
    txtstream.WriteLine (strRecord)

Expert Comment

ID: 12063932
    If you are looking to use the text files as your database, my first link should help you. You can have ADO read the existing data into a recordset, (if the file doesnt exist create an empty recordset) add records to it and save it back out to the text file. ADO can handle the entire file for you.


Author Comment

ID: 12295356
Dear all ,

After long time I want your help for this problem again .
I will give you more details about this.

Dear  ysagada1012 , you code sample is working some extent.

In my VBA I have some text boxes. Users will enter data in to that . In my text document ( like database) I want save these entering data as records .
I will give you example for my feilds .


I would like to have the fields whitout any blank between the fields
e.g      080480001302CRXU 159001 8.... and so on
CUSORDE      pos  1 - 7
Line no      pos  8 - 10
Index            pos 11 - 12
Connos      pos 13 -

Please help me to solve this problem .


LVL 59

Accepted Solution

Julian Hansen earned 400 total points
ID: 12295775

Ok, it looks like what you want is a file with fixedlength fields. However this will mean you might have to have spaces if all the fields are not exactly the required length.

For example if you have to store the values cat dog and horse in field 1 that is 5 charactes wide you will have to space pad (or pad with some other character) the values cat and dog so that they fill up the full 5 spaces.

What you need to do is to look at the comments above and draw from those. For each record you want to write you need to build up a string as ysagada1012 suggested except what you need to do is format each field to the required length

Dim Output as String
Dim fileout as SomeSortOfFileObject ' Refer above for options example Dim fileout as Scripting.FileSystemObject
Dim field1 as String
Dim field2 as String

' Open file as text for appending- refer to posts above

field1 = ctrl1.text
field2 = ctrl2.text

' You can probably do this a bit more elegantly

field1 = field1 & Space$(7 - len(ctrl1.text)
field2 = field2 & Sapce$(3 - len(ctrl2.text)

' Add CR/LF to the output string

OutputString = field1 & field2 & ... & Chr(13) & Chr(10)

' Assumes you have opened a file for appending text somewhere previsously - refer to previous posts on how to do this

fileout.WriteLine ( OutputString )

' Close file

This is basically what you need to do.

Author Comment

ID: 12306505
Dear all ,

I can manage with your ponts . If any new requirment comes , I will contact you all .

I will greatly appreciate assistance that you all gave me .

Thanks every body .

PChandima .


Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn different types of Android Layout and some basics of an Android App.
Simple Linear Regression
Introduction to Processes

715 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