Jump to content
Macro Express Forums

text file and variable assistance


djashdj
 Share

Recommended Posts

Alright... i'm looking for some pro assistance on this basic problem.

 

I've got a text file I want to process. It is a running log accessed by another application. When key words appear I want specific commands to occur.

 

The log file from the other application does not clear itself. It also is held active by the application. So I start my macro by copying the file to another name.

 

LOGFILE.txt becomes LOG2.TXT. In summation the basic idea of the macro is below.

 

copy file logfile.txt log2.txt

I process log2.txt

if variable t1 contains "xyz"

text box display "it works"

end if

end process

delete file log2.txt

 

Meanwhile the LOGFILE.txt continues to grow with new data. When I run the macro again it processes the entire log file.

 

What I want it to do is process the last LINE of the log file. The log file is not a CSV, or TAB delimited file. It's essentially a basic text document... that is... SPACE delimited.

 

What I'd love to do is take the last line and enter EACH space delimited section into a T1, T2, T3 variable. So if the text file looked like this:

 

Hello My Name Is Julio123

My Brain hurts because I have too many pets.

 

If my macro is searching for BRAIN it will work. But as time goes on there may be more lines and the macro will look like this.

 

 

Hello My Name Is Julio123

My Brain hurts because I have too many pets.

Since yesterday I got a new job.

 

Now the macro will still trigger but I don't want it to. I want it to only process the LAST line or Row.

 

Ideally placing each word into a different %T%.

 

About 11 years ago I was using macro express do do this. I remember putting the entire line into a string. I can't for the life of me remember how I did this and of course I don't have my old macro.

 

Anyone have any ideas?

Link to comment
Share on other sites

In order to get it to only process the last line of the text file here is what I've done.

 

begin file process

variable modify integer: %N1% = %N1% + 1

end file process

begin file process start at N1

end file process

 

So basically it runs through the file increasing the line count then i process the same file again only this time starting at the last line.

 

Hopefully this doesn't get too slow as the file gets large. (few megabytes probably) If anyone knows a more efficient way to just read the last line I'm all ears.

 

Also a way of getting space delimited fields as mentioned in the first post to T1 T2 T3 etc that would be great.

 

Thanks!

 

-d

Link to comment
Share on other sites

If my macro is searching for BRAIN it will work. But as time goes on there may be more lines and the macro will look like this.

 

 

Hello My Name Is Julio123

My Brain hurts because I have too many pets.

Since yesterday I got a new job.

I presume you mean the log file "will look like this" rather than the macro?

 

So basically it runs through the file increasing the line count then i process the same file again only this time starting at the last line.

Your use of the phrase "last line" suggests that your file is not space delimited after all, but that each line has at its end a carriage return and linefeed (ascii 13 + ascii 10). If you really mean space delimited, then each of the 21 words in the text above would parse into a separate variable or record. So the last sentence "Since yesterday I got a new job." would be separated into 7 variables or records. How on earth could the macro relate these 7 words as a "sentence", as opposed to, say, "many pets. Since yesterday I got a new job."?

Please explain better exactly what you mean.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...