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.yahoo.com/getPlaylist.php?
node_id=6566264&bitrate=1500&tech=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.yahoo.com/domkernel/2.0/cache/callisto/CosmosAssetInfo?
ustr=2240994&asset_id=2-2//sonybravia/apnews/0222dv_mn_bus_crash&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.yahoo.com/getPlaylist.php?node_id=6566264&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.yahoo.com/getPlaylist.php?node_id=6565493&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.yahoo.com/getPlaylist.php?node_id=6564203&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
4 2401
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. - Public Function ReplaceText(ByVal txt As String, ByVal from_str As String, ByVal to_str As String) As String
-
Dim result As String
-
Dim from_len As Integer
-
Dim pos As Integer
-
-
from_len = Len(from_str)
-
Do While Len(txt) > 0
-
' Find from_str.
-
pos = InStr(txt, from_str)
-
If pos = 0 Then
-
' No more occurrences.
-
result = result & txt
-
txt = ""
-
Else
-
' Make the replacement.
-
result = result & Left$(txt, pos - 1) & to_str
-
txt = Mid$(txt, pos + from_len)
-
End If
-
Loop
-
-
ReplaceText = result
-
End Function
-
-
-
dim data as string
-
dim aux as string
-
dim output as string
-
-
dim progress as integer
-
-
Open "c:/pathtoyourfile/log111.txt" for input as #1 'open file
-
-
do until eof(1)
-
-
-
line input #1, data ' read log line by line
-
-
-
'here you can try more conditions
-
-
if left(data,1) <> "-" or mid(data,2,7) = "[MP M]" then
-
-
-
aux = ReplaceText ( data, "6 [MP M] Last file decoded - " to "") ' replace some text
-
-
' if you whant to replace more text
-
' aux = replacetext ( aux , moretext, "")
-
' try to make several replacments until your logfile get clean format.
-
-
output = output & aux & chr(13)
-
-
end if
-
-
-
loop
-
-
close #1
-
-
Open "c:/pathtoyourfile/log111-aux.txt" for output as #1 'open aux file
-
-
print #1, output
-
-
close #1
-
-
-
'################################################
-
-
progress = 50
-
-
dim GroupData ' store the number of records in uour future database
-
-
dim varTitle, varFilename, varNode_id, varFileBitRate, varInstantDowload, varAverageDownload
-
dim varNumOftimrebuff, varPlaybackRebuf, varDownloadRebuff
-
-
Open "c:/pathtoyourfile/log111.txt-aux" for input as #1 'open aux file
-
-
do until eof(1)
-
-
-
line input #1, data ' read log line by line
-
-
if left(data,5) <> "Title" then
-
-
varTitle = mid(data,9,len(data))
-
GroupData = GroupData + 1
-
-
end if
-
-
if left(data,8) <> "Filename" then varFilename = mid(data,12,len(data))
-
if left(data,7) <> "node_id" then varNode_id = mid(data,9,len(data))
-
-
'.... complete conditiond for all the fields
-
-
'now you can use an recordset to update database
-
'point your recordset to GroupData value (data1.recordset.row = GroupData)
-
'navigate trow the recordset and update fields with values from the above variables
-
-
-
loop
-
-
progress = 99
-
-
close #1
-
-
progress = 100
...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... -
SplitPos = Instr(Text, "=")
-
If SplitPos = 0 Then ' No "=" found.
-
Skip to next line
-
End If
-
TheField = Trim(Left(Text, SplitPos - 1))
-
Details = Trim(Mid(Text, SplitPos + 1))
-
Select Case TheField
-
Case "Title"
-
' Save any existing entry, and start a new entry.
-
MyRecordSet("Title") = Details
-
Case "Filename"
-
MyRecordSet("Filename") = Details
-
...
-
End Select
-
This is just off the top of my head of course, so don't take it as Gospel.
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... -
If Left(data,5) <> "Title" Then varTitle = ...
-
If Left(data,8) <> "Filename" then varFilename = ...
-
If Left(data,7) <> "node_id" then varNode_id = ...
-
Doesn't it seem likely that in many cases, all of these tests would be true?
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... -
If Left(data,5) <> "Title" Then varTitle = ...
-
If Left(data,8) <> "Filename" then varFilename = ...
-
If Left(data,7) <> "node_id" then varNode_id = ...
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |