Solved

Creating ASCII file

Posted on 2004-09-13
15
393 Views
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 .

PChandima
0
Comment
Question by:PChandima
  • 4
  • 3
  • 2
  • +3
15 Comments
 
LVL 2

Expert Comment

by:Parsi
Comment Utility
Hi

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

Parsi
0
 

Author Comment

by:PChandima
Comment Utility
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
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
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
 
LVL 1

Expert Comment

by:Bestdev
Comment Utility
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
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
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
 

Author Comment

by:PChandima
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Expert Comment

by:Bestdev
Comment Utility
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
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
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
 

Expert Comment

by:ysagada1012
Comment Utility
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
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
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
 

Author Comment

by:PChandima
Comment Utility
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
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 100 total points
Comment Utility
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
 

Author Comment

by:PChandima
Comment Utility
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEvens challenge 6 63
VB 6.0 printer how to align 6 49
File.WriteAllLines problem at random C# ASP.NET 6 53
Path to Python 9 37
A short article about a problem I had getting the GPS LocationListener working.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now