I have a text file that contains data I need to insert into an Excel file.
I have found a way to search for the specific starting line of my data; however, I need to find a way to detect the final line of data.
This is what a few lines of my data would look like:
#0001: Job description 01/19/08
Step 1: do this 01/22/08
Step 2: do this after 01/24/08
Step 3: do this after after 01/29/08
#0002: Job description 02/19/08
Step 1: do this 02/22/08
Step 2: do this after 02/24/08
Step 3: do this after after 02/29/08
#0003: Job description 03/19/08
Step 1: do this 03/22/08
Step 2: do this after 03/24/08
Step 3: do this after after 03/29/08
For example, I can already find job number 0002. What I want to do is send to excel cell number R1C1 all data between #0002 and the final date.
How can i find the line that the next "#" symbol starts on? If I know the line number that the next "#" symbol starts on, I can then store and combine each line after #0002 in a variable but stop before getting to the next job description #0003.
How can i find the line that the next "#" symbol starts on?
Is there an easier way?
The job numbers are NOT sequential.
may return my starting character, yes?
MidStr>
find first character of line
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
So just loop through the file combiningg each line until you find a line beginning with a #. At that point send the combined lines to Excel, reset the output var and continue. Like this:
This particular example will output the combined lines for job1, then job2 and then job3.
Code: Select all
ReadFile>d:\jobs.txt,inFile
Separate>inFile,CRLF,lines
Let>k=0
Let>combined=
Repeat>k
Let>k=k+1
Let>this_line=lines_%k%
Position>#,this_line,1,p
If>p=1
//found line starting with #,
If>combined<>
//output combined to Excel .. but use a messagemodal here as example
MessageModal>combined
Endif
//reset combined
Let>combined=
Else
Let>combined=%combined%%this_line%
Endif
Until>k=lines_count
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 12
- Joined: Mon Mar 10, 2008 6:26 pm
I have a couple more questions if you don't mind answering them.
After all of the lines have been combined into a single line of text, such as the above code does, is it possible to enter soft returns that will simulate the ALT-ENTER that is in excel. I would like to have a crlf in between each line for excel but the crlf doesnt seem to work.
Is it possible for macro scheduler to convert a .pdf document to a text file?
After all of the lines have been combined into a single line of text, such as the above code does, is it possible to enter soft returns that will simulate the ALT-ENTER that is in excel. I would like to have a crlf in between each line for excel but the crlf doesnt seem to work.
Is it possible for macro scheduler to convert a .pdf document to a text file?
Is it possible to grab the last 8 characters of text from a predetermined line?
to be more specific, for example:
#0001: Job description 9/19/07 10/29/08
Step 1: do this 9/19/07
Step 2: do this after 10/24/08
Step 3: do this after after 10/29/08
Once I know what line #0001 exists on, is there a way to store only the last 8 characters, the finishing date, into a variable?
to be more specific, for example:
#0001: Job description 9/19/07 10/29/08
Step 1: do this 9/19/07
Step 2: do this after 10/24/08
Step 3: do this after after 10/29/08
Once I know what line #0001 exists on, is there a way to store only the last 8 characters, the finishing date, into a variable?
Thats great. Works like a charm. Thank you much, JRL for that snippet.JRL wrote:Once you have the line in a variable use length> to get the length (number of characters in the line). subtract 7 from the length. then use the result in a MidStr>
///(assuming the line is in variable "line")
Length>line,len
Sub>len,7
Midstr>line,%len%,8,LastEight
MDL>LastEight