Solved

How i'm gonna extract data from text logfile into VB?

Posted on 2003-12-07
8
222 Views
Last Modified: 2010-05-03
Hi experts,

i have this kind of text logfile..

12/12/2003           09.01am            50mV
12/12/2002           09.02am            65mV
12/12/2003           09.03am            72mV

it have 3 columns (date, time , temp). Between date and time, time and temp.. they are seperated with one tab.

How i goona take data in each column at every line? meaning that, at first line, i want to take date, time and temp.
For date and time, i can take the whole string (12/12/2003, 09.01am) because it is not a value. For temp, i need the value to substitute into my formula in VB. so i need to seperate mV from the integer so that it would become a valid value. If that is difficult, how about i want to seperate this .. 50 mV <-- it has one white space between integer and unit. Can it be done?

Please help me..

thanks
0
Comment
Question by:mr_avril
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 9894990
Private Sub Form_Load()
    Dim inputString As String
    Dim values As Variant
    Dim timeStamp As Date
    Dim voltage As Integer
   
    Open App.Path & "\Data.txt" For Input As #1
    Do While Not EOF(1)
        Line Input #1, inputString
        values = Split(inputString, Chr(9))
       
        timeStamp = CDate(values(0) & " " & Replace(values(1), ".", ":"))
        voltage = Val(values(2))
       
        Debug.Print timeStamp, voltage
    Loop
    Close #1
End Sub
0
 
LVL 10

Expert Comment

by:anv
ID: 9895833
'if u can use commas to separate the columns the following code
'wud be easy to use..

Set rsTxt = New ADODB.Recordset
           
'fpath is the full path of the text file you want to open
'cn a connection object
            cn.Open "Provider=Microsoft.Jet" _
                    & ".OLEDB.4.0;Data Source=" & fpath _
                    & ";Extended Properties='text;HDR=NO;" _
                    & "FMT=Delimited'"

'fname is the Name of the text file to open

rsTxt.Open "select * from [" & fName & "#txt]", cn, adOpenStatic, _
                  adLockReadOnly, adCmdText
'now use the recordset to fetch data from the file
'as u use 4 DBMS..
0
 

Author Comment

by:mr_avril
ID: 9895897
sorry anv.. i'm very new to VB.. i don't understand what u means..
and idle_mind.. great coding.. but i cannot run it.. it give error..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9896565
What was the error?
0
 
LVL 27

Expert Comment

by:planocz
ID: 10217761
Hi mr_avril,

This  code will read in file into a buffer and read one line at a time.Then it will oarse the line to find
your mV value.

Private Sub Parsing_to_New()
  Dim sRecord         As String
  Dim sParse          As String
  Dim sBuffer         As String
  Dim iReadfile       As Integer
  Dim iMyValue      As Integer
 
 
  'Open and read old file
  iReadfile = FreeFile
  Open "c:\YourFile.TXT" For Input As #iReadfile
  Do Until EOF(iReadfile)
     '******** read file into a buffer string ******************
     Select Case LOF(iReadfile) - Seek(iReadfile)
       Case 0
              If sParse = "" Then
                Exit Do
              End If
              If InStr(sParse, vbLf) = 0 Then
                Exit Do
              End If
      'This size is for a 1.44 Disc
      Case Is >= 142000
               sBuffer = Input(LOF(iReadfile) - Seek(iReadfile) + 1, iReadfile)
               sParse = sParse & sBuffer
      Case Is < 142000
              On Error Resume Next
              sBuffer = Input(LOF(iReadfile) - Seek(iReadfile) + 1, iReadfile)
              sParse = sParse & sBuffer
   End Select
    '*********** read string *******************************
   While InStr(sParse, vbLf)          '<----- Read one line at a time
       sRecord = Left(sParse, InStr(sParse, vbLf) - 1)  '<--- This will show you each line
       sParse = Mid(sParse, InStr(sParse, vbLf) + 1)    '<--- This will show you the whole file
       Debug.Print sRecord      '<---- Add to VB Watch to see how it works
       Debug.Print sParse      '<---- Add to VB Watch to see how it works
   If InStr(sRecord, "mV") Then
         iMyValue = Mid(sRecord, InStr(sRecord, "mV") - 2, 2)
   End If
   Print #iOutfile, sRecord
   Wend
Loop
     Close #iReadfile
  End Sub
0
 
LVL 27

Expert Comment

by:planocz
ID: 10217776
I for got to remove line....
 
Print #iOutfile, sRecord

from the example code...
Please remove that line for the code to run without errors.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month6 days, 17 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question