pulling a time stamp from a txt file

user11536789

I have a txt file log that has user input timestamps. I am writing a code that I can search through the txt file for a word and pull the time stamp associated with that word. The time stamp looks like this

+work=2019-08-30|08:41| [IRP] Diagnose

I would like to be able to input the word (in this case Diagnose) and the program pull the time stamp from the line and put it in cell A1. My current code can find Diagnose if its alone (ie no timestamp) but for some reason doesn't recognize Diagnose in the timestamp line. Here is the code that i have started. I am looking for recommendation on how to be able to type in Diagnose into my search message box and the result in cell A1 is 2019-08-30|08:41| Thanks for any help you can provide

Sub Scan()

Dim stdesfile As String
Dim stdataline As String


stdesfile = Application.GetOpenFilename
Find = InputBox("which word")
Open stdesfile For Input As #1

Do While Not EOF(1)
   Input #1, stdataline
   If stdataline = Find Then
      bFound = True
      Exit Do
   End If
Loop

If bFound = True Then
   MsgBox "Item Found"
Else
  MsgBox "Item not found"
End If

Close #1

End Sub
Michał Turczyn

Try below code (assuimg the date format is fixed to be 17 characters length):

Sub Scan()

Dim stdesfile As String
Dim stdataline As String
Dim idx As Long, dt As String

stdesfile = Application.GetOpenFilename
Find = InputBox("which word")
Open stdesfile For Input As #1

Do While Not EOF(1)
   Input #1, stdataline
   If InStr(1, stdataline, Find) > 0 Then
      idx = InStr(1, stdataline, "=")
      dt = Mid(stdataline, idx + 1, 17)
      bFound = True
      Exit Do
   End If
Loop

If bFound = True Then
   MsgBox "Item Found, date: " + dt
Else
  MsgBox "Item not found"
End If

Close #1

End Sub

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Getting epoch time from gmt time stamp

分類Dev

remove specific characters from time stamp

分類Dev

Preserving original time stamp of uploaded file in Azure Blob Storage

分類Dev

Unix Time stamp creation in C from custom data fields

分類Dev

Pulling a random word/string from a line in a text file in python

分類Dev

Can the time stamp of a Retweet be accessed?

分類Dev

How to find time stamp and decimal value reading from data stream in Java

分類Dev

Reading variable from txt file

分類Dev

Downloading links from a txt file

分類Dev

Reading from a txt file in Java

分類Dev

Pulling from a worktree?

分類Dev

Cassandra time stamp returns 0 rows

分類Dev

How to log Serial data with time stamp?

分類Dev

How to stamp prompt at command execute time?

分類Dev

How is the time stamp number in /etc/shadow calculated?

分類Dev

Pulling data from a website (livebox)

分類Dev

RxJs Observable from backed with pulling

分類Dev

From tibble to txt or excel file in R

分類Dev

Login on java based from txt file

分類Dev

awk script to read data from txt file

分類Dev

Extracting from excel (.xlsx) writing to .txt file

分類Dev

Read individual parts from HTML .txt file

分類Dev

Creating a dictionary in python from txt file

分類Dev

Reverse a String by reading from a txt file

分類Dev

Array/List from txt file in Python

分類Dev

Recursively Read from a .txt file Java

分類Dev

Searching data from txt file in iOS

分類Dev

Load rectangle data from txt file with Python?

分類Dev

Particle Tracking by coordinates from txt file