Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2001
    Posts
    92

    Remove blank lines

    Listed below is part of a sample code someone posted for AMS4, the code deletes blank lines from a text file. I am now trying to see if I can do the same in AMS5 Pro but I am having difficulty finding equivalent actions . Here is the AMS4 code I am trying to duplicate:

    %LineCount% = TextFile.CountLines ("%TempDir%\myfile.txt")
    %Ctr% = "0"
    WHILE (%Ctr% < %LineCount% )
    %TextLine% = TextFile.GetLine ("%TempDir%\myfile.txt", %Ctr%)
    IF (%TextLine% = "")
    TextFile.DeleteLine ("%TempDir%\myfile.txt", %Ctr%)
    %LineCount% = Evaluate (%LineCount% - 1)
    ELSE
    %Ctr% = Evaluate (%Ctr% + 1)
    END IF
    END WHILE

    Do I need to use both Tables and Paragraphs?

  2. #2
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Something like this might work

    Code:
    tblTextFile = TextFile.ReadToTable("filename.ext")
    for index, row in tblTextFile do
    	if row == "" then
    		tblTextFile = Table.Remove(tblTextFile, index)
    	end
    end
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  3. #3
    Join Date
    Apr 2001
    Posts
    92
    TJ_Tigger, thanks for the help. I am still having some difficulty trying to add your code into a really cool sample project from Autorun.org called "Text File and Tables". Download

    I want to add a button that will remove all blank lines and display the results in the paragraph window. I will do some more reading and experimenting and hopefully I will be able to figure it out soon!

  4. #4
    Join Date
    Apr 2001
    Posts
    92
    I am trying to delete blank lines from a text file. I am getting this error "On Click Line 10: Argument 1 must be of type table." This is Line 10: "tFileContents = Table.Remove(tFileContents, index)."

    Thanks,

    Here is what I have so far:

    tFiles = Dialog.FileBrowse(true, "Browse", "", "Text Files (*.txt)|*.txt|", "", "", false, true);
    if tFiles and tFiles[1] ~= "CANCEL" then

    for index, row in tFileContents do
    if row == "" then
    tFileContents = Table.Remove(tFileContents, index)
    end
    end

  5. #5
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    You missed reading the file into a table like Tig suggested.

    Code:
    tFiles = Dialog.FileBrowse(true, "Browse", "", "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])     
      --*************************************
    
      for index, row in tFileContents do 
        if (String.TrimLeft(row, " ") == "") or (String.TrimLeft(row, " ") == "\r\n") then 
          tFileContents = Table.Remove(tFileContents, index) 
        end 
      end
    end
    Last edited by Worm; 03-29-2004 at 12:09 PM.

  6. #6
    Join Date
    Apr 2001
    Posts
    92
    Worm, could I be something else? I tried your code in a new project and I get the error about "Argument 1 must be of type table" with some text files but not others.
    Seems like if there is a blank line in the text file, then I will get the error although that did not happen with another file. Strange...

  7. #7
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    I really need to start testing this stuff before I post it

    Try this:

    Code:
    tFiles = Dialog.FileBrowse(true, "Browse", "", "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])     
      --*************************************
    
      for index, row in tFileContents do 
        if (String.TrimLeft(row, " ") == "") or (String.TrimLeft(row, " ") == "\r\n") then 
          result = Table.Remove(tFileContents, index) 
        end 
      end
    end

  8. #8
    Join Date
    Apr 2001
    Posts
    92
    I am trying to see the results by adding the following line after your code:

    Code:
    Paragraph.SetText("Paragraph1", result);
    I did create a paragraph object, but looks like the code is deleting everything, not just blank lines. Am I missing something?

  9. #9
    Join Date
    Apr 2001
    Posts
    92
    I am trying to see the results by adding the following line after your code:

    Code:
    Paragraph.SetText("Paragraph1", result);
    I did create a paragraph object, but looks like the code is deleting everything, not just blank lines. Am I missing something?

  10. #10
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    The results are in the table tFileContents not in the variable result

    do this:
    Code:
    tFiles = Dialog.FileBrowse(true, "Browse", "", "Text Files (*.txt)|*.txt|", "", "", false, true); 
    
    --you only need to check tFiles1] for CANCEL
    if tFiles[1] ~= "CANCEL" then 
    
      --*************************************
      tFileContents = TextFile.ReadToTable(tFiles[1])     
      --*************************************
    
      for index, row in tFileContents do 
        if (String.TrimLeft(row, " ") == "") or (String.TrimLeft(row, " ") == "\r\n") then 
          result = Table.Remove(tFileContents, index) 
        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

  11. #11
    Join Date
    Apr 2001
    Posts
    92

    Thumbs up

    Worm and TJ_Tigger, thanks for all the help!!! It is working great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts