Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 3 of 3

Thread: Table Trouble

  1. #1
    Join Date
    Apr 2006
    Posts
    127

    Huh? Table Trouble

    If I read my text file into a Table, each table index contains a line from the text file, correct? What I need to do is be able to use a specific line with other functions, but although the Help seems to suggest that an individual index will be accepted as a string, this does not work when the string is created by TextFile.ReadToTable.

    So, I thought this might work:

    tTable = {};
    tTable = TextFile.ReadToTable(MyInfo);
    sTable = Table.Remove(tTable, 1);

    Table.Remove invokes an error:

    On Preload, Line 171: Argument 1 must be of type table.


    Now, tTable[1], for example, contains a string (first line of the text file) but the following fails too:

    sNewString = String.Concat("MyPrefix = \"", tTable[1]);

    So what is the correct way to use a table value that contains a string, as a string?

  2. #2
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    If you get the error that argument 1 is not a table, then your ReadToTable() action failed. As a result, Table.Remove(tTable, 1) and String.Concat("MyPrefix = \"", tTable[1]) will both fail. Add some error checking, like this:

    Code:
    if File.DoesExist(MyInfo) then
      tTable = TextFile.ReadToTable(MyInfo);
      error = Application.GetLastError();
      if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
      else
        local line = Table.Remove(tTable, 1);
        error = Application.GetLastError();
        if (error ~= 0) then
          Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
        else
          Dialog.Message("Info", "The first line of text is: " .. line, MB_OK);
        end
      end
    else
      Dialog.Message("Error", "File '" .. MyInfo .. "' does not exist!", MB_OK, MB_ICONEXCLAMATION); 
    end
    Ulrich
    Last edited by Ulrich; 04-12-2011 at 08:52 PM. Reason: Added even more error checking

  3. #3
    Join Date
    Apr 2006
    Posts
    127
    Thanks for your help Ulrich. It is in fact a hit and miss thing, I suspect that the misses occur if the file contains an unexpected character. So on this occasion I have written an external exe to perform the task and pass a 'known to be pure ascii' string back to Suf, which works 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