View Full Version : Need help with text file
Pretender
06-06-2004, 12:11 PM
I have a logfile and i want to remove blank lines in the logfile.So when i print the logfile, 2 logfiles print at one page(63 lines)somtimes a logfile is larger than 32 lines then only one logfile comes at one page............. i had made it with ams 4.0 but it takes 1 hour to remove the lines when i had 100 or 200 logfiles....the problem is with ams 5.0 ....i dont understand how to made this......
Intrigued
06-06-2004, 05:16 PM
The link below contains possible solutions (at least in part) to what you are trying to accomplish in AMS 5.
This should help get you on the right track, at the least.
http://www.indigorose.com/forums/showthread.php?t=7012&highlight=remove+blank+lines
Pretender
06-08-2004, 10:24 AM
yes i have seen this example....but i i must search for a word and delete the next line......not delete all blank lines...........
TJ_Tigger
06-08-2004, 11:57 AM
Pretender, what words are you wanting to search for in the text file? By reading the text file into a table you can then go line by line through the table and remove the blank line after any line which contains the keyword you want to search for. If you have more than one keyword I would suggest using a table to define the keywords as part of your search.
For example:
tFiles = Dialog.FileBrowse(true, "Browse", "AutoPlay\\Docs", "Text Files (*.txt)|*.txt|", "", "", false, true);
--you only need to check tFiles[1] for CANCEL
if tFiles[1] ~= "CANCEL" then
--*************************************
tFileContents = TextFile.ReadToTable(tFiles[1])
--*************************************
--KeyWords = {"Alarm","Abort","Data log", "description", "machine no."};
KeyWords = {"Data log", "description", "machine no."};
for kwindex, keyword in KeyWords do
for index, row in tFileContents do
if String.Find(row, keyword, 1, true) ~= -1 then
Table.Remove(tFileContents, index + 1)
end
end
end
--Build a variable that contains the tables content
strFile=""
for index, row in tFileContents do
strFile = strFile .. row .. "\r\n"
end
Paragraph.SetText("Paragraph1", strFile)
end
Hope this helps. I have attached a sample project as well. You may want to add a line that check to make sure that the line you are removing is actually blank.
Tigg
Intrigued
06-08-2004, 01:00 PM
Thank you TJ for the assist... I was in the middle of formulating my reply, but it got busy at the 'shop'. I have some nicely colored Paragraph boxes though that were to be apart of my example solution, to show 'before' and 'after' snap shots. (grin)
This objective is something I would like to accomplish myself! I am glad it was brought up.
TJ_Tigger
06-08-2004, 03:24 PM
No Problem, Just thought I would pipe in where I could. I have done something similar to this with another project.
Tigg
Pretender
06-09-2004, 08:00 AM
thanks for the help....this is the right way.......but i dont think that i can finish the poject.....its tooooooo complicate for me....every second logfile (at abort) i must delete one line as it is in the Logfile_print.txt.And and the big problem is that the logfiles can be larger than this in the sample then only one logfile can be printed at one page...... :rolleyes
:rolleyes :rolleyes
Pretender
06-19-2004, 03:07 PM
I have an error messege......dont understand why......i have removed lines in every second logfile......and i checked if there is a long logfile but now i had an error messege.......can somone help???
csd214
06-20-2004, 03:56 PM
I started your app and got an error message at line 68, but I don’t think this is “true”. Why: There is a mismatch of if/for and end statement. My personal advice: Adjust your code with proper TAB indents after if and for. When you have a paragraph like this:
if String.Find(row, keyword, 1, true) ~= -1 then
index = index + 1
Table.Remove(tFileContents, index)
end
Mark the two lines between if and end; press TAB. It’s easier to view the code when the lines are indented. I think the “end” at line 90 should be removed. Lines 91-137 are empty lines?
You are looking for some keywords. But why “Abort” two times? Your code:
KeyWords = {"Abort","Abort","description", "machine no."};
You are deleting the NEXT line (index = index + 1). You will have en error when “next line” doesn’t exist. You should count the number of lines:
RowCount = Table.Count(tFileContents);
and add an if statement:
if index < RowCount then
removed = Table.Remove(tFileContents, index)
--Debug.Print("Removed = "..removed..”\r\n”);
end
Use the debug facilities. Start your code with:
Debug.ShowWindow(true);
Debug.SetTraceMode(true); --eventually
and add Debug.Print() where appropriate.
It should be easier to remove ALL blank lines instead of removing the line after "Abort","description", "machine no." But I’m not sure whether I have the correct understanding of what you want to achieve.
I learned something new from your project: How to hide an object at design time.
Good luck!
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.