Changing TEXT FILES into Access Tables
-
Hi everyone, I need help with converting Text Files into Access table and hope you can help me out. I have 2 TEXT FILES, first that contains the table name, and its attribues, and the SECOND file contains the values of the table. So if the first TEXT FILE that has the following table values: tablename field1, integer field2, string field3, integer field4, string then another TEXT FILE will contains the values for the table: 1, john, 6, smith 2, steve, 7, clark 3, carrie, 8, wayne 4, dan, 9, chait 5, erin, 10, alan what i need to do is to read the values from the FIRST TEXT FILE that contains the table attributes and create the table. Then i need to read the SECOND TEXT FILE and plug in the values. so at the end, i'll have a Access table like: field1 field2 field3 field4 1 john 6 smith 2 steve 7 clark 3 carrie 8 wayne 4 dan 9 chait 5 erin 10 alan But i need the readings of BOTH TEXT FILES to be dynamic so it'll work if the TEXT FILE has x number of columns, and x number of rows. and i also need the reading to be dynamic so it can read the values from the SECOND TEXT FILE no matter what kind of values it contains, ie, integer, string, char, etc... If anyone can help me out, Please let me know. Thanks in Advance. Steve
-
Hi everyone, I need help with converting Text Files into Access table and hope you can help me out. I have 2 TEXT FILES, first that contains the table name, and its attribues, and the SECOND file contains the values of the table. So if the first TEXT FILE that has the following table values: tablename field1, integer field2, string field3, integer field4, string then another TEXT FILE will contains the values for the table: 1, john, 6, smith 2, steve, 7, clark 3, carrie, 8, wayne 4, dan, 9, chait 5, erin, 10, alan what i need to do is to read the values from the FIRST TEXT FILE that contains the table attributes and create the table. Then i need to read the SECOND TEXT FILE and plug in the values. so at the end, i'll have a Access table like: field1 field2 field3 field4 1 john 6 smith 2 steve 7 clark 3 carrie 8 wayne 4 dan 9 chait 5 erin 10 alan But i need the readings of BOTH TEXT FILES to be dynamic so it'll work if the TEXT FILE has x number of columns, and x number of rows. and i also need the reading to be dynamic so it can read the values from the SECOND TEXT FILE no matter what kind of values it contains, ie, integer, string, char, etc... If anyone can help me out, Please let me know. Thanks in Advance. Steve
Here is some code to read the files ... I don't know anything about creating the access database though. first in your header file, add the member function :
void get_field(void); // get the next field in the line
// puts into variable : field
// assumes that fields are separated
// by commasadd to the top of your .CPP file :
#include <fstream.h> // for file i/o
Add the following to the top of your .CPP file (or add as member variables in your .H file) :
#define MAX_CHAR 80 // maximum number of characters per input line
char field[MAX_CHAR]; // temporary, current field
char tmp[MAX_CHAR]; // temporary, the entire line read in
int start; // temporary, place to start looking for
// the next field in the line#define MAX_FIELDS 20 // maximum number of fields
int numFields; // actual number of fields
CString tableName; // table name
CString fieldName[MAX_FIELDS]; // names of the fields
int fieldCode[MAX_FIELDS]; // 0 = int 1 = float 2 = CString
Here is the code to read the first file, and determine the number of fields and the type of each field :
// first ... read the definition file ifstream infile; infile.open("test1.txt"); numFields = 0; infile.getline(tmp,MAX\_CHAR); start = 0; get\_field(); tableName = field; while (!infile.eof()) { infile.getline(tmp,MAX\_CHAR); if (infile.eof()) break; start = 0; get\_field(); fieldName\[numFields\] = field; get\_field(); CString fieldType; fieldType = field; fieldType.MakeLower(); fieldType.TrimLeft(); fieldType.TrimRight(); if (fieldType == "integer") fieldCode\[numFields\] = 0; if (fieldType == "float") fieldCode\[numFields\] = 1; if (fieldType == "string") fieldCode\[numFields\] = 2; numFields++; } infile.close();
Here is the code to read the second file, and determines the value of each field for each record. Write out to a third file to make sure that everything is correct :
// next ... read the value file // (open an output file to make sure we are reading correctly) infile.open("test2.txt"); ofstream outfile; outfile.open("test3.txt"); int num\_records = 0; while (!infile.eof()) {
-
Here is some code to read the files ... I don't know anything about creating the access database though. first in your header file, add the member function :
void get_field(void); // get the next field in the line
// puts into variable : field
// assumes that fields are separated
// by commasadd to the top of your .CPP file :
#include <fstream.h> // for file i/o
Add the following to the top of your .CPP file (or add as member variables in your .H file) :
#define MAX_CHAR 80 // maximum number of characters per input line
char field[MAX_CHAR]; // temporary, current field
char tmp[MAX_CHAR]; // temporary, the entire line read in
int start; // temporary, place to start looking for
// the next field in the line#define MAX_FIELDS 20 // maximum number of fields
int numFields; // actual number of fields
CString tableName; // table name
CString fieldName[MAX_FIELDS]; // names of the fields
int fieldCode[MAX_FIELDS]; // 0 = int 1 = float 2 = CString
Here is the code to read the first file, and determine the number of fields and the type of each field :
// first ... read the definition file ifstream infile; infile.open("test1.txt"); numFields = 0; infile.getline(tmp,MAX\_CHAR); start = 0; get\_field(); tableName = field; while (!infile.eof()) { infile.getline(tmp,MAX\_CHAR); if (infile.eof()) break; start = 0; get\_field(); fieldName\[numFields\] = field; get\_field(); CString fieldType; fieldType = field; fieldType.MakeLower(); fieldType.TrimLeft(); fieldType.TrimRight(); if (fieldType == "integer") fieldCode\[numFields\] = 0; if (fieldType == "float") fieldCode\[numFields\] = 1; if (fieldType == "string") fieldCode\[numFields\] = 2; numFields++; } infile.close();
Here is the code to read the second file, and determines the value of each field for each record. Write out to a third file to make sure that everything is correct :
// next ... read the value file // (open an output file to make sure we are reading correctly) infile.open("test2.txt"); ofstream outfile; outfile.open("test3.txt"); int num\_records = 0; while (!infile.eof()) {
-
Here is some code to read the files ... I don't know anything about creating the access database though. first in your header file, add the member function :
void get_field(void); // get the next field in the line
// puts into variable : field
// assumes that fields are separated
// by commasadd to the top of your .CPP file :
#include <fstream.h> // for file i/o
Add the following to the top of your .CPP file (or add as member variables in your .H file) :
#define MAX_CHAR 80 // maximum number of characters per input line
char field[MAX_CHAR]; // temporary, current field
char tmp[MAX_CHAR]; // temporary, the entire line read in
int start; // temporary, place to start looking for
// the next field in the line#define MAX_FIELDS 20 // maximum number of fields
int numFields; // actual number of fields
CString tableName; // table name
CString fieldName[MAX_FIELDS]; // names of the fields
int fieldCode[MAX_FIELDS]; // 0 = int 1 = float 2 = CString
Here is the code to read the first file, and determine the number of fields and the type of each field :
// first ... read the definition file ifstream infile; infile.open("test1.txt"); numFields = 0; infile.getline(tmp,MAX\_CHAR); start = 0; get\_field(); tableName = field; while (!infile.eof()) { infile.getline(tmp,MAX\_CHAR); if (infile.eof()) break; start = 0; get\_field(); fieldName\[numFields\] = field; get\_field(); CString fieldType; fieldType = field; fieldType.MakeLower(); fieldType.TrimLeft(); fieldType.TrimRight(); if (fieldType == "integer") fieldCode\[numFields\] = 0; if (fieldType == "float") fieldCode\[numFields\] = 1; if (fieldType == "string") fieldCode\[numFields\] = 2; numFields++; } infile.close();
Here is the code to read the second file, and determines the value of each field for each record. Write out to a third file to make sure that everything is correct :
// next ... read the value file // (open an output file to make sure we are reading correctly) infile.open("test2.txt"); ofstream outfile; outfile.open("test3.txt"); int num\_records = 0; while (!infile.eof()) {
-
Here is some code to read the files ... I don't know anything about creating the access database though. first in your header file, add the member function :
void get_field(void); // get the next field in the line
// puts into variable : field
// assumes that fields are separated
// by commasadd to the top of your .CPP file :
#include <fstream.h> // for file i/o
Add the following to the top of your .CPP file (or add as member variables in your .H file) :
#define MAX_CHAR 80 // maximum number of characters per input line
char field[MAX_CHAR]; // temporary, current field
char tmp[MAX_CHAR]; // temporary, the entire line read in
int start; // temporary, place to start looking for
// the next field in the line#define MAX_FIELDS 20 // maximum number of fields
int numFields; // actual number of fields
CString tableName; // table name
CString fieldName[MAX_FIELDS]; // names of the fields
int fieldCode[MAX_FIELDS]; // 0 = int 1 = float 2 = CString
Here is the code to read the first file, and determine the number of fields and the type of each field :
// first ... read the definition file ifstream infile; infile.open("test1.txt"); numFields = 0; infile.getline(tmp,MAX\_CHAR); start = 0; get\_field(); tableName = field; while (!infile.eof()) { infile.getline(tmp,MAX\_CHAR); if (infile.eof()) break; start = 0; get\_field(); fieldName\[numFields\] = field; get\_field(); CString fieldType; fieldType = field; fieldType.MakeLower(); fieldType.TrimLeft(); fieldType.TrimRight(); if (fieldType == "integer") fieldCode\[numFields\] = 0; if (fieldType == "float") fieldCode\[numFields\] = 1; if (fieldType == "string") fieldCode\[numFields\] = 2; numFields++; } infile.close();
Here is the code to read the second file, and determines the value of each field for each record. Write out to a third file to make sure that everything is correct :
// next ... read the value file // (open an output file to make sure we are reading correctly) infile.open("test2.txt"); ofstream outfile; outfile.open("test3.txt"); int num\_records = 0; while (!infile.eof()) {
I suggest to consult the book Inside Visual C++ by Kruglinsky. In this book the basics of ODBC an DAO acces is dealt with.