473,408 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

TXT file to MDB, CSV

Hi all,

I have some music songs in .txt format. The file names are 1.txt,
2.txt, 3.txt, etc. The fortmat of the .txt files are as follows:
------------Format starts------------
%
\startsong
\stitle{Song Title}%
\film{Film Name}%
\year{Year}%
\starring{Star Cast}%
\singer{Singers}%
\music{Musician}%
\lyrics{Lyricist}%
%
% Contributor:
% Transliterator:
% Credits:
% Editor:
%
\printtitle
#indian
%
song line 1
song line 2
song line 3
song line 4

song line 5
song line 6
%
#endindian
\endsong
%
------------Format ends------------

Can someone help in:
(1) Opening the first file
(2) Each line of the .txt file to be converted as a different field in
a new file NEWFILE
(3) Open the next file and repeat point (2)
(4) The subsequent files should all be appended to the same NEWFILE

Will appreciate any help rendered. This effort is to catalog the
collection as a database for personal use and not meant for me to make
any commercial gains.

Regards,

Ninad.
Nov 13 '05 #1
6 1745
Not knowing your experience level, you could put this sub on a button:

Private Sub Import()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strLine As String

Set db = CurrentDb

strFileName = "1.txt"
Open strFileName For Input As #1

Set rs = db.OpenRecordset("tblSongs", dbOpenDynaset)
rs.AddNew

Line Input #1, strLine
rs!startsong = startsong

Line Input #1, strLine
rs!stitle = strLine

.....continue for each variable

rs.Update
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
Close #1
End Sub

"Ninad" <ni***********@hotmail.com> wrote in message
news:2a**************************@posting.google.c om...
Hi all,

I have some music songs in .txt format. The file names are 1.txt,
2.txt, 3.txt, etc. The fortmat of the .txt files are as follows:
------------Format starts------------
%
\startsong
\stitle{Song Title}%
\film{Film Name}%
\year{Year}%
\starring{Star Cast}%
\singer{Singers}%
\music{Musician}%
\lyrics{Lyricist}%
%
% Contributor:
% Transliterator:
% Credits:
% Editor:
%
\printtitle
#indian
%
song line 1
song line 2
song line 3
song line 4

song line 5
song line 6
%
#endindian
\endsong
%
------------Format ends------------

Can someone help in:
(1) Opening the first file
(2) Each line of the .txt file to be converted as a different field in
a new file NEWFILE
(3) Open the next file and repeat point (2)
(4) The subsequent files should all be appended to the same NEWFILE

Will appreciate any help rendered. This effort is to catalog the
collection as a database for personal use and not meant for me to make
any commercial gains.

Regards,

Ninad.

Nov 13 '05 #2
Hi,

Not very good at programming, but tried to incorporate the code. I get
the error message at
Dim db As DAO.Database
Dim rs As DAO.Recordset as User-defined type not defined

Just a few other queries,

(1) Should I place this code in the module and call this funtion from
a button ? or
(2) insert this code in the On Click event of the button.

I'll try to work around this in the mean time. But thanks for taking
the time to help.

Regards,

Ninad.

"miTcheLL" <mitchell@"no_spam".topsideinc.com> wrote in message news:<1096807294.5Ox3uJjD7Pt5KhznEYkeLQ@teranews>. .. Not knowing your experience level, you could put this sub on a button:

Private Sub Import()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strLine As String

Set db = CurrentDb

strFileName = "1.txt"
Open strFileName For Input As #1


----------message snipped
Nov 13 '05 #3
On 3 Oct 2004 21:01:07 -0700, ni***********@hotmail.com (Ninad) wrote:

Make sure you have a reference (code window / tools / references) to
Microsoft DAO <highest version>.
You can probably remove the reference to ADO that's already there.

1 or 2: either one would work. If you intend to use the code from this
one form only, I would put it in the form.

-Tom.

Hi,

Not very good at programming, but tried to incorporate the code. I get
the error message at
Dim db As DAO.Database
Dim rs As DAO.Recordset

as User-defined type not defined

Just a few other queries,

(1) Should I place this code in the module and call this funtion from
a button ? or
(2) insert this code in the On Click event of the button.

I'll try to work around this in the mean time. But thanks for taking
the time to help.

Regards,

Ninad.

"miTcheLL" <mitchell@"no_spam".topsideinc.com> wrote in message news:<1096807294.5Ox3uJjD7Pt5KhznEYkeLQ@teranews>. ..
Not knowing your experience level, you could put this sub on a button:

Private Sub Import()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strLine As String

Set db = CurrentDb

strFileName = "1.txt"
Open strFileName For Input As #1


----------message snipped


Nov 13 '05 #4
Hi,
Managed to get it to work. Only problem is there are 3250 such files
with file names as 1.txt, 2.txt ....... 3250.txt

When I use a for .. to loop and create a string such that all the
files can be done at one go, the file name gets created as below

The actual file name is "C:\PATH\1.txt" but instead a space gets
inserted before the 1 and gets generated as "C:\PATH\ 1.txt" The code
used is as follows

For varCounter = 1 to 3250
strFileName = chr(34) + "C:\PATH\" + str(varCounter) + chr(34)

Open strFileName............
..
..
..
..
..

Next

Anything wrong that needs mending.

Thanks for all the assistance.

Ninad.

-------------message snipped-------------

"miTcheLL" <mitchell@"no_spam".topsideinc.com> wrote in message news:<1096897397.zgzN4uvsyTs0vp8L75/QVQ@teranews>...
You need to check the reference to Microsoft DAO and move it up as far as it
will go in the references check list.
You would best place be behind a button on a form that performs the import.

miTch

Nov 13 '05 #5
Ninad wrote:
Hi,
Managed to get it to work. Only problem is there are 3250 such files
with file names as 1.txt, 2.txt ....... 3250.txt

When I use a for .. to loop and create a string such that all the
files can be done at one go, the file name gets created as below

The actual file name is "C:\PATH\1.txt" but instead a space gets
inserted before the 1 and gets generated as "C:\PATH\ 1.txt" The code
used is as follows

For varCounter = 1 to 3250
strFileName = chr(34) + "C:\PATH\" + str(varCounter) + chr(34)

Open strFileName............
..
..
..
..
..

Next

Anything wrong that needs mending.


Use & instead of + for concatenation, there are subtle differences, you
should then also avoid the str() as a) it's not necessary when using "&"
and b) that's the cause of the space, it's the space for the sign, by
default a space instead of a + sign for positive. Not sure you want the
quotes either...

strFileName = "C:\PATH\" & varCounter

--
Pretentious? Moi?
Nov 13 '05 #6
ni***********@hotmail.com (Ninad) wrote in message news:<2a**************************@posting.google. com>...
Hi,
Managed to get it to work. Only problem is there are 3250 such files
with file names as 1.txt, 2.txt ....... 3250.txt

When I use a for .. to loop and create a string such that all the
files can be done at one go, the file name gets created as below

The actual file name is "C:\PATH\1.txt" but instead a space gets
inserted before the 1 and gets generated as "C:\PATH\ 1.txt" The code
used is as follows

For varCounter = 1 to 3250
strFileName = chr(34) + "C:\PATH\" + str(varCounter) + chr(34)

Open strFileName............


Ninand,
How about...

Public Sub CreateFiles(ByVal strPath As String, ByVal intStart As
Integer, ByVal intStop As Integer)
Const sFILE = "MYTEXT"
Dim intCounter As Integer

If Right$(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If

For intCounter = intStart To intStop
Debug.Print strPath & sFILE & intCounter & ".txt"
Next intCounter

End Sub

Modify to suit your needs, obviously.

HTH,
Pieter
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.