473,387 Members | 1,517 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,387 software developers and data experts.

Log file import

171 100+
Hi All
I am back with another issue.
I have an ACCESS DB which used to import a process log (.log extension). The VBA code was fine until now but there was few new field names and values are added in the process log file and now the code is not importing all the records to the database table.
I have attached a sample of the log file. To attach in this post I have changed the file extension to .txt. Normally it is .log file. Earlier the log has entries upto the the below line.
NUM REGPOINTS = 4
TEST1 (Unknown)
TEST2 (2014-06-11 10:20:00) ETO
TEST3 (2014-06-11 10:28:56) ETO
TEST4 (2014-06-11 10:31:44) ETO.
And the new process starts with a first line similar to below line
2014-06-11 10:20:18 PROS_TST: New System LOG changed:

But now some process has additions like below two lines after the NUM REGPOINTS and then the first line starts.
ORIGINAL REGS = TEST1 (Unknown)
ORIGINAL REGX = TEST4 (2014-06-11 10:31:44) ETO
Some entries may have NUM REGPOINTS=0 and then the new fields appear like below. then the first line of another process entry will be available
ORIGINAL REGS =
ORIGINAL REGX =
2014-06-11 10:22:35 PROS_TST: New System LOG changed:
In that case also code works.
I doubt about the "Buf=10" mentioned in the code stops importing anything when NUM REGPOINTS= any other value than 0 (because that time there is no = sign for the test1, test2, test3 records
Hope I have explained my issue.
Please help me to make the code import the new log file.
The code as follows:
Expand|Select|Wrap|Line Numbers
  1. Function ImportLOG(AddPth)
  2. On Error GoTo ErrRtn
  3. Dim hfile As Integer
  4. Dim MainRs As Recordset
  5. Dim fldName As String
  6. Dim fldValue As String
  7. Dim txtLine As String
  8. Dim DOF As String
  9. Dim DateGroup As String
  10. Dim FirstLine As Boolean
  11. Dim i As Integer
  12. Dim TempUIDs As String
  13. Dim TempAtTime As String
  14. Dim TempByWhom As String
  15. Dim TempWhat As String
  16. Dim Buf As Byte
  17. Dim CharNo As Long
  18. Dim NoOfChrs As Long
  19. Dim x As Variant
  20.  
  21. DoCmd.Hourglass True
  22. DOF = Format(Forms!startpage!txtImDate, "ddmmmyyyy")
  23. DateGroup = Format(Forms!startpage!txtImDate, "yyyymm_dd")
  24. hfile = FreeFile()
  25. Set MainRs = CurrentDb.OpenRecordset("LogTbl", dbOpenDynaset, dbAppendOnly)
  26. Open LogPath & AddPth & "logs_" & DateGroup & ".log" For Binary As hfile '
  27. NoOfChrs = LOF(hfile)
  28. x = Now()
  29. Do While Not EOF(hfile)
  30. DoEvents
  31. Forms!startpage!lblProcess.Caption = "Processing ... " & Format(CharNo / NoOfChrs * 100, "00.00") & "% - Character " & CharNo & " of " & NoOfChrs & " (uidq = " & TempUIDs & ")"
  32. Forms!startpage.Repaint
  33.  
  34. InputUnixLine:
  35.    txtLine = ""
  36.    Do
  37. NextChr:
  38.       Get #hfile, , Buf
  39.  
  40.       CharNo = CharNo + 1
  41.  
  42.       If Buf = 13 Then GoTo NextChr
  43.       If Buf = 10 Then Exit Do
  44.  
  45.       If EOF(hfile) Then GoTo SkipProc
  46.       txtLine = txtLine & Chr$(Buf)
  47.  
  48.    Loop
  49.    If txtLine = "" Then
  50.       If MainRs.EditMode = dbEditNone Then
  51.          MainRs.AddNew
  52.       Else
  53.          MainRs!LogDate = Forms!startpage!txtImDate
  54.          MainRs.Update
  55.       End If
  56.       GoTo InputUnixLine 'jump to read next line
  57.    End If
  58.  
  59.    If Val(Left(txtLine, 4)) = Year(Now()) Or Val(Left(txtLine, 4)) = Year(Now()) - 1 Then FirstLine = True
  60.  
  61.    If FirstLine Then
  62.       If Trim(Mid(txtLine, InStr(21, txtLine, ":") + 1)) = "" Then
  63.          FirstLine = False
  64.          GoTo InputUnixLine 'jump to read next line
  65.       End If
  66.       MainRs.AddNew
  67.       MainRs!AtTime = Left(txtLine, 19)
  68.       MainRs!ByWhom = Trim(Mid(txtLine, 21, InStr(21, txtLine, ":") - 21))
  69.       MainRs!What = Trim(Mid(txtLine, InStr(21, txtLine, ":") + 1))
  70.       TempAtTime = Left(txtLine, 19)
  71.       TempByWhom = Trim(Mid(txtLine, 21, InStr(21, txtLine, ":") - 21))
  72.       TempWhat = Trim(Mid(txtLine, InStr(21, txtLine, ":") + 1))
  73.       FirstLine = False
  74.       GoTo InputUnixLine 'jump to read next line
  75.    End If
  76.  
  77.    If InStr(txtLine, "=") = 0 Then
  78.       If MainRs.EditMode = dbEditNone Then
  79.          MainRs.AddNew
  80.       End If
  81.       MainRs!REG_DETAIL = Trim(txtLine)
  82.       MainRs!UIDS = TempUIDs
  83.       MainRs!AtTime = TempAtTime
  84.       MainRs!ByWhom = TempByWhom
  85.       MainRs!What = TempWhat
  86.       MainRs!LogDate = Forms!startpage!txtImDate
  87.       MainRs.Update
  88.       GoTo InputUnixLine
  89.    Else
  90.  
  91.       fldName = Trim(Left(txtLine, InStr(txtLine, "=") - 1))
  92.       fldValue = Trim(Mid(txtLine, InStr(txtLine, "=") + 1))
  93.  
  94.    End If
  95.  
  96.  
  97.    Select Case fldName
  98.    Case "ARRIVAL TIME"
  99.       MainRs!ATIME = fldValue
  100.    Case "EST. TIME OF ENTRY"
  101.       MainRs!ETIME = fldValue
  102.   Case "COORDINATED EXIT TIME"
  103.   MainRs!CTIME = fldValue
  104.   Case "PREVIOUS REG"
  105.   MainRs!REG = fldValue
  106.   Case "NEXT REG"
  107.   MainRs!NREG = fldValue
  108.   Case "NUM REGPOINTS"
  109.   MainRs!NUM_REG = fldValue
  110.    Case "ORIGINAL REGS"
  111.   MainRs!ORG_REG = fldValue
  112.   Case "ORIGINAL REGX"
  113.   MainRs!ORG_REX = fldValue
  114.    Case "UIDs"
  115.    MainRs.Fields(fldName) = fldValue
  116.    TempUIDs = MainRs!UIDS
  117.    Case Else
  118.    MainRs.Fields(fldName) = fldValue
  119.    End Select
  120.  
  121. SkipProc:
  122. Loop
  123. Forms!startpage!lblProcess.Caption = "Complete: Time taken " & Format(Now() - x, "nn:ss") & ". " & Format(CharNo / NoOfChrs * 100, "00.00") & "% - Character " & CharNo & " of " & NoOfChrs & " (SFPI = " & TempUIDs & ")"
  124. Forms!startpage.Repaint
  125.  
  126. EndRtn:
  127. Close hfile
  128. MainRs.Close
  129. Set MainRs = Nothing
  130. DoCmd.Hourglass False
  131. Exit Function
  132.  
  133. ErrRtn:
  134. Select Case Err.Number
  135. Case 3020
  136.    MsgBox "Complete", vbInformation, "Data Import"
  137.    GoTo EndRtn
  138. Case 53
  139.    MsgBox Err.Description, vbExclamation, "Import Data"
  140.    GoTo EndRtn
  141. Case Else
  142.    MsgBox Err.Number & " " & Err.Description
  143.    Stop
  144.    Resume Next
  145. End Select
  146. Resume
  147.  
  148. End Function


>Text from attached Log.txt file.
Expand|Select|Wrap|Line Numbers
  1. 2014-06-11 10:18:18 PROS_TST: New System LOG inserted:
  2.    UIDs                   = 1
  3.    ARRIVAL TIME           = 2014-06-11 10:43:08
  4.    EST. TIME OF ENTRY     = 2014-06-11 10:20:00
  5.    COORDINATED EXIT TIME  = Unknown
  6.    PREVIOUS REG           = 
  7.    NEXT REG               = 
  8.    NUM REGPOINTS          = 4
  9.                             TEST1 (Unknown) 
  10.                             TEST2 (2014-06-11 10:20:00) ETO
  11.                             TEST3 (2014-06-11 10:28:56) ETO
  12.                             TEST4 (2014-06-11 10:31:44) ETO
  13.    ORIGINAL REGS          = TEST1 (Unknown) 
  14.    ORIGINAL REGX          = TEST4 (2014-06-11 10:31:44) ETO
  15. 2014-06-11 10:30:18 PROS_TML: New System LOG updated:
Attached Files
File Type: txt logs_201409_01.txt (702 Bytes, 231 views)
Sep 2 '14 #1
2 1289
jforbes
1,107 Expert 1GB
Rajeevs, are you getting an error of any kind? What happens when you run the code?

You are correct, the code you provided doesn’t account for lines that begin with "TEST". I would guess it attempts to insert a new blank record for each of these lines, which hopefully gets rejected by your database constraints.

A cheap and sleazy workaround would be to change lines 77-94 to:
Expand|Select|Wrap|Line Numbers
  1.     If Left(Trim(txtLine), 4) <> "TEST" Then
  2.         If InStr(txtLine, "=") = 0 Then
  3.             If MainRs.EditMode = dbEditNone Then
  4.                MainRs.AddNew
  5.             End If
  6.             MainRs!REG_DETAIL = Trim(txtLine)
  7.             MainRs!UIDS = TempUIDs
  8.             MainRs!AtTime = TempAtTime
  9.             MainRs!ByWhom = TempByWhom
  10.             MainRs!What = TempWhat
  11.             MainRs!LogDate = Forms!startpage!txtImDate
  12.             MainRs.Update
  13.             GoTo InputUnixLine
  14.          Else
  15.  
  16.             fldName = Trim(Left(txtLine, InStr(txtLine, "=") - 1))
  17.             fldValue = Trim(Mid(txtLine, InStr(txtLine, "=") + 1))
  18.  
  19.          End If
  20.     End If
This should change the code to ignore the lines beginning with “TEST”, but you might want to address these new additions to your Log File as they look important.
Sep 2 '14 #2
rajeevs
171 100+
Thank you jforbes
It can be anything after that NUM REGPOINTS field if the value greater than 0. If NUM REGPOINTS = 0 then the next fields will be like below
ORIGINAL REGS =
ORIGINAL REGX =
And that time my old code works fine. But most of the time the NUM REGPOINTS will have a value greater than 0 and there will some lines corresponding to the number and then the ORIGINAL REGS & ORIGINAL REGX appear.
So I cannot ignore the values after the NUM REGPOINTS
Sep 3 '14 #3

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

Similar topics

1
by: Bethany Holliday | last post by:
Hi all, I have a file with an extension of .sdf. I "believe" it is a text file of some sort but I am uncertain. The source agency hasn't returned any of my calls so I'm wondering if anyone is...
2
by: David Berry | last post by:
Hi All. I'm looking for any help or sample code that can show me how to make a file import wizard in ASP.NET (VB preferred) like the one that MS Access uses. I'm working on a web site where the...
5
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can...
3
by: Danny | last post by:
Trying to import a couple of fields from an excel spreadsheet into an Access 2000 database by extracting needed fields and pasting them into a new spreadsheet, I can import the data into a new...
2
by: Salad | last post by:
When I attempt to import/link a text file, I select the type of file as TextFiles, select the text file, and hit the Import or Link button. No specification file is presented and nothing gets...
7
by: Joe Fallon | last post by:
I am importing a delimited ASCII text file into a dataset using OLEDB. I set up the connection and dataadapter and then fill the dataset. It works - sort of. It turns out that some of my data is...
1
by: GB | last post by:
Hello: I need to import an Excel file to SQL Server. The .xls file has the column names which contains dot inside, like AAA.BBB. When I import this file in SQL using DTS Import/Export tool, it...
10
by: Avi | last post by:
Hi I need to read in a large set of text files (9GB+ each) into a database table based on fixed width lengths. There are several ways to complete this, but I am wondering if anyone has...
1
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...
2
by: SDEBEUL | last post by:
Hi, I have a complex text file import issue. The first 13 lines of the file need to be skipped. Then each of the next 2 lines need to be combined in one record. the format of one record...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
Oralloy
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 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.