473,789 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import txt file with vertical fields into access db

1 New Member
I have not done programming in a very long time and what is worst, I never learned VB. Although my job does not require this knowledge, I cam across a problem that although it seemed simple it has become a nightmare.

There is a log that gets generated in a regular basis and need to put most , but not all its contents in a DB (new or existent, it doesn't matter). because the fields that I need to cover are vertically and there is junk in the file, I the wizards nor the Macros in Access or Excel 2003 seem to be much help. The log file looks like this (log111.txt)

---------------------------------------------------------------------------------------------------------------
:¿G 6 [SIG2] sigmaInit() initialized RUA by calling avis_init()
6 [CLST] Can't open semaphore: No such file or directory
7 [OPRA] Registered TVCSYS/AVIS callback
6 [MP M]
6 [MP M] *************** ******* File Playback Statistics *************** ***********
6 [MP M] Total number files played and exited = 1 files
6 [MP M] Total number files that required rebuffering = 0 files
6 [MP M] Total rebuffering percentage = 0.000000%
6 [MP M]
6 [MP M] Last file decoded - Title = 5-year-old boy left alone dies in fire
6 [MP M] Last file decoded - Filename = http://cosmos.bcst.yah oo.com/getPlaylist.php ?

node_id=6566264 &bitrate=1500&t ech=wmv
6 [MP M] Last file decoded - File bitrate = 1475 kbps
6 [MP M] Last file decoded - Instantaneous download speed = 4047 kbps
6 [MP M] Last file decoded - Average download speed = 3509 kbps
6 [MP M]
6 [MP M] Last file decoded - Number of times file rebuffered = 0 times
6 [MP M] Last file decoded - Playback time at last rebuffering event = 0 sec.
6 [MP M] Last file decoded - Download speed at last rebuffering event = 0 kbps
6 [MP M] *************** *************** *************** *************** **************
6 [MP M]
6 [ ] TODO_VEC plGetFile url:

http://digitalhome.yah oo.com/domkernel/2.0/cache/callisto/CosmosAssetInfo ?

ustr=2240994&as set_id=2-2//sonybravia/apnews/0222dv_mn_bus_c rash&link_speed =3000
6 [MP M]
6 [MP M] *************** ******* File Playback Statistics *************** ***********
6 [MP M] Total number files played and exited = 2 files
6 [MP M] Total number files that required rebuffering = 0 files

----------------------------------------------------------------------------------------------------------------
I can clean it up to look like this

Title = 5-year-old boy left alone dies in fire
Filename = http://cosmos.bcst.yah oo.com/getPlaylist.php ?node_id=656626 4&bitrate=1500& tech=wmv
File bitrate = 1475 kbps
Instantaneous download speed = 4047 kbps
Average download speed = 3509 kbps

Number of times file rebuffered = 0 times
Playback time at last rebuffering event = 0 sec.
Download speed at last rebuffering event = 0 kbps


Title = Woman charged in fatal Minn. bus crash
Filename = http://cosmos.bcst.yah oo.com/getPlaylist.php ?node_id=656549 3&bitrate=1500& tech=wmv
File bitrate = 1461 kbps
Instantaneous download speed = 4502 kbps
Average download speed = 4003 kbps

Number of times file rebuffered = 0 times
Playback time at last rebuffering event = 0 sec.
Download speed at last rebuffering event = 0 kbps


Title = Snow and ice covering much of northeast
Filename = http://cosmos.bcst.yah oo.com/getPlaylist.php ?node_id=656420 3&bitrate=1500& tech=wmv
File bitrate = 1482 kbps
Instantaneous download speed = 4018 kbps
Average download speed = 3665 kbps

Number of times file rebuffered = 0 times
Playback time at last rebuffering event = 0 sec.
Download speed at last rebuffering event = 0 kbps
--------------------------------------------------------------------------------------------------------------
and the DB fields need to be (each unique record contains):

Title
Filename
File bitrate
Instantaneous download speed
Average download speed
Number of times file rebuffered
Playback time at last rebuffering event
Download speed at last rebuffering event

This may be a simple code,but I am sorry to say I have not been able to find teh solution and I appreciate anyone's help.

Regards
Feb 29 '08 #1
4 2425
cardei
5 New Member
Hi,

I hope than the next pice of code will help you to solve the problem.
It's not tested becouse I don't have VB instaled on this locacion write now and I write the code with notepad, but I thing that you will get the idea.

Sory for my english.



Expand|Select|Wrap|Line Numbers
  1. Public Function ReplaceText(ByVal txt As String, ByVal from_str As String, ByVal to_str As String) As String
  2. Dim result As String
  3. Dim from_len As Integer
  4. Dim pos As Integer
  5.  
  6.     from_len = Len(from_str)
  7.     Do While Len(txt) > 0
  8.         ' Find from_str.
  9.         pos = InStr(txt, from_str)
  10.         If pos = 0 Then
  11.             ' No more occurrences.
  12.             result = result & txt
  13.             txt = ""
  14.         Else
  15.             ' Make the replacement.
  16.             result = result & Left$(txt, pos - 1) & to_str
  17.             txt = Mid$(txt, pos + from_len)
  18.         End If
  19.     Loop
  20.  
  21.     ReplaceText = result
  22. End Function
  23.  
  24.  
  25. dim data as string
  26. dim aux as string
  27. dim output as string
  28.  
  29. dim progress as integer
  30.  
  31. Open "c:/pathtoyourfile/log111.txt" for input as #1 'open file
  32.  
  33. do until eof(1)
  34.  
  35.  
  36.     line input #1, data ' read log line by line
  37.  
  38.  
  39.     'here you can try more conditions 
  40.  
  41.     if left(data,1) <> "-" or mid(data,2,7) = "[MP M]" then     
  42.  
  43.  
  44.         aux = ReplaceText ( data, "6 [MP M] Last file decoded - " to "") ' replace some text
  45.  
  46.         ' if you whant to replace more text
  47.         ' aux = replacetext ( aux , moretext, "") 
  48.         ' try to make several replacments until your logfile get clean format.
  49.  
  50.         output = output & aux & chr(13)
  51.  
  52.     end if
  53.  
  54.  
  55. loop
  56.  
  57. close #1
  58.  
  59. Open "c:/pathtoyourfile/log111-aux.txt" for output as #1 'open aux file
  60.  
  61. print #1, output
  62.  
  63. close #1
  64.  
  65.  
  66. '################################################ 
  67.  
  68. progress = 50
  69.  
  70. dim GroupData ' store the number of records in uour future database
  71.  
  72. dim varTitle, varFilename, varNode_id, varFileBitRate, varInstantDowload, varAverageDownload
  73. dim varNumOftimrebuff, varPlaybackRebuf, varDownloadRebuff
  74.  
  75. Open "c:/pathtoyourfile/log111.txt-aux" for input as #1 'open aux file
  76.  
  77. do until eof(1)
  78.  
  79.  
  80.     line input #1, data ' read log line by line
  81.  
  82.     if left(data,5) <> "Title" then 
  83.  
  84.         varTitle = mid(data,9,len(data))
  85.         GroupData = GroupData + 1
  86.  
  87.     end if
  88.  
  89.     if left(data,8) <> "Filename" then varFilename = mid(data,12,len(data))
  90.     if left(data,7) <> "node_id" then  varNode_id = mid(data,9,len(data))
  91.  
  92.     '.... complete conditiond for all the fields
  93.  
  94.     'now you can use an recordset to update database
  95.     'point your recordset to GroupData value (data1.recordset.row = GroupData)
  96.     'navigate trow the recordset and update fields with values from the above variables
  97.  
  98.  
  99. loop
  100.  
  101. progress = 99
  102.  
  103. close #1
  104.  
  105. progress = 100
Mar 1 '08 #2
Killer42
8,435 Recognized Expert Expert
...There is a log that gets generated in a regular basis and need to put most , but not all its contents in a DB ...
I'm afraid I haven't read cardei's code. But in general, I think that a direct "import" won't be possible. You will need to read the file and extract the details yourself.

The overall logic should be relatively simple. You just start reading lines from the (cleaned) file, and for each line do something along these lines...

Expand|Select|Wrap|Line Numbers
  1. SplitPos = Instr(Text, "=")
  2. If SplitPos = 0 Then ' No "=" found.
  3.   Skip to next line
  4. End If
  5. TheField = Trim(Left(Text, SplitPos - 1))
  6. Details = Trim(Mid(Text, SplitPos + 1))
  7. Select Case TheField
  8.   Case "Title"
  9.     ' Save any existing entry, and start a new entry.
  10.     MyRecordSet("Title") = Details
  11.   Case  "Filename"
  12.     MyRecordSet("Filename") = Details
  13.   ...
  14. End Select
  15.  
This is just off the top of my head of course, so don't take it as Gospel.
Mar 3 '08 #3
Killer42
8,435 Recognized Expert Expert
cardei, I haven't had time to read through your code in detail. But I did see some logic there that worried me. Specifically, it seems as though you're using "<>" in place of "=". See this code...

Expand|Select|Wrap|Line Numbers
  1. If Left(data,5) <> "Title" Then varTitle = ...
  2. If Left(data,8) <> "Filename" then varFilename = ...
  3. If Left(data,7) <> "node_id" then  varNode_id = ...
  4.  
Doesn't it seem likely that in many cases, all of these tests would be true?
Mar 3 '08 #4
cardei
5 New Member
cardei, I haven't had time to read through your code in detail. But I did see some logic there that worried me. Specifically, it seems as though you're using "<>" in place of "=". See this code...

Expand|Select|Wrap|Line Numbers
  1. If Left(data,5) <> "Title" Then varTitle = ...
  2. If Left(data,8) <> "Filename" then varFilename = ...
  3. If Left(data,7) <> "node_id" then  varNode_id = ...
  4.  
Doesn't it seem likely that in many cases, all of these tests would be true?

Hi,

yes is true, sory but I write the code very quik in notepad and yes I put "<>" wher "=" must be.

Sory again for the error, anyway I hope you can find somthing usefull in the code, I meen maybe the algorithm is ok. I thing that with this idea you can import your logfile to a database.

Excuse my English, I lern english now.

Best regards.
Mar 7 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1826
by: Olivier Noblanc ATOUSOFT | last post by:
Hello, In the botom of this post you will see my source code. The problem is when i launch main.py that doesn't make anything why ? Thanks olivier noblanc Atousoft http://www.logiciel-erp.fr
1
9756
by: DCM Fan | last post by:
Access 2K, SP3 on Windows 2K, SP4 All, I have an import spec set up with quoted Identifiers and comma-separated values. The text file is produced by a 3rd-party program of which I have no control. It outputs all text fields surrounded by quotes, and all numeric fields w/o quotes. All fields are separated with commas. This has been working for 2 years, until today, when one of the data fields
1
8184
by: mark | last post by:
In Access 2000 and 2002, I have created an import specification to import the fixed-width recordset below into an existing table. I am having strange problems with the import of the date and time fields. 177 102003 16:43:12 102003 18:43:12 6OAG0ADP Y 0000 0000 0000 0000 61930 4HGA800 165 102003 17:43:12 102003 18:44:12 6OAG0ADP Y 0000 0000 0000 0000 61930 4HGA800 177 102003 16:41:18 102003 18:45:12 6OAG0ADP Y 0000 0000 0000 0000 61930...
20
2769
by: Steve Jorgensen | last post by:
Hi all, I've just finished almost all of what has turned out to be a real bear of a project. It has to import data from a monthly spreadsheet export from another program, and convert that into normalized data. The task is made more difficult by the fact that the structure itself can vary from month to month (in well defined ways). So, I used the SQL-centric approach, taking vertical stripes at a time so that, for instance, for each...
2
3758
by: VMI | last post by:
In Access, when a user's going to import a fixed-width format ascii file, a window in the "Import Text Wizard" lets the user "mark" where in a string one field will begin and end (with the vertical lines that can be moved with the mouse). Can this (or something similar) be implemented in order for the user to graphically choose which part of the string will be, for example, be displayed in a MessageBox? So for example, my control would...
0
3479
by: NewbieSupreme | last post by:
I'm using PHPMyAdmin on an Apache2Triad install (latest version; 5.x.x, which installs PHP5 and PHPMyAdmin 2.8 as well). In Access, I exported a table to a text file, tab-delimited, text qualifyer of "none" (this is how I read to do it from newsgroups). When I use the Query window in phpmyadmin to import the text file, it waits a while, then returns an error: #1064 - You have an error in your SQL syntax; check the manual that...
1
4184
by: Child of His | last post by:
I have been through every trick I know, or has been suggested. I have a one to two million line fixed field database in text format. I want to bring it into Access 97. When I use the external data import, the list of files to import does not include text files of any type, only other database formats. On a 102,000 line text file, I was able to split it with Word 97, import the split files into Excel 97 one at a time, and then save...
1
8716
by: baling | last post by:
Hi.... Hi everybody, i have a code that i make in VBA and know I want to use this code in to VB6. But i don't know how to use that code in to VB 6.0 Please correct this code so i can use it in VB 6.0. Code: --- use in mainform ------- Option Compare Database Option Explicit
7
12076
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
9663
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10195
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.