• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

Creating ASCII file

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 .

PChandima
0
PChandima
Asked:
PChandima
  • 4
  • 3
  • 2
  • +3
1 Solution
 
ParsiCommented:
Hi

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

Parsi
0
 
PChandimaAuthor Commented:
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 .

PChandima
0
 
Julian HansenCommented:
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

http://www.officecomputertraining.com/vbtutorial/tutpages/page24.asp
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
BestdevCommented:
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: www.functionx.com

Ayman
0
 
Dang123Commented:
PChandima,
    Perhaps these may help.

Export an ADO Recordset to a Text File
http://www.freevbcode.com/ShowCode.Asp?ID=548

Class to Export Database Tables to Text File
http://www.freevbcode.com/ShowCode.Asp?ID=1323

Dang123
0
 
PChandimaAuthor Commented:
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 .

PChandima
0
 
BestdevCommented:
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.

Ayman
0
 
Julian HansenCommented:
PChandima,

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

http://www.officecomputertraining.com/vbtutorial/tutpages/page24.asp

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.
0
 
ysagada1012Commented:
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)
    txtstream.Close
0
 
Dang123Commented:
PChandima,
    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.

Dang123
0
 
PChandimaAuthor Commented:
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 .

Ex : CUSORDE , LINENO, INDEX , CONNON etc.

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 -
etc.

Please help me to solve this problem .

Thanks

Pchandima
0
 
Julian HansenCommented:
PChandima,

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

Example
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
etc

' 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)
etc

' 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.
0
 
PChandimaAuthor Commented:
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 .

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 4
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now