Indigo Rose Software

Professional Software Development Tools

 
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 26

Thread: déjà vu

  1. #1
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014

    déjà vu

    I've brought this up before, sorry, I just can't seem to work through it.
    I get an error stating:
    On click, line 32: attempt to index feild '?'(a number value)
    the red below shows the line. Help please.

    -- step 1: connect anonymously to your web site.com
    FTP.Connect("www.diginetx.com", "logon", "password", "", true);
    err = Application.GetLastError();
    if err ~= FTP.OK then
    Dialog.Message("Error", _tblErrorMessages[err]);
    end

    --step 2: change to the directory where the file you want is located
    FTP.ChangeDir("websites/diginetx.com/docs/folder1/folder2");
    err = Application.GetLastError();
    if err ~= FTP.OK then
    Dialog.Message("Error", _tblErrorMessages[err]);
    end

    ftp_file_result = FTP.ListFiles();

    --stop the listbox from updating
    ListBox.SetUpdate("DirList", false);

    -- empty the listbox
    ListBox.DeleteItem("DirList",LB_ALLITEMS);

    tbFiles = FTP.ListFiles();

    -- add each item to the listbox in this format:
    -- <name>
    for numIndex, tblInfo in tbFiles do
    --if String.SplitPath(tbFiles.Name).Extension == ".zip" then
    if String.SplitPath(tbFiles[numIndex]["Name"]).Extension == ".zip" then
    ListBox.AddItem("DirList", tblInfo.Name .. "");

    end

    --allow the listbox to update
    ListBox.SetUpdate("DirList", true);

    FTP.Disconnect ();
    end

  2. #2
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Bump Com'on ya old salts! Where is this thing jacked up?

  3. #3
    Join Date
    Jul 2007
    Posts
    158
    Quote Originally Posted by Bruce View Post
    if String.SplitPath(tbFiles[numIndex]["Name"]).Extension == ".zip" then
    I haven't FTP Plugin here but i think you should try this

    Code:
    if String.Right(tbFiles[numIndex].Name, 3) == "zip" then

  4. #4
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Quote Originally Posted by arb View Post
    I haven't FTP Plugin here but i think you should try this

    Code:
    if String.Right(tbFiles[numIndex].Name, 3) == "zip" then
    Hey arb thanks for the reply! But... nope , same error message.

  5. #5
    Join Date
    Dec 2004
    Location
    Texas
    Posts
    239
    Try changing:
    Code:
    if String.SplitPath(tbFiles[numIndex]["Name"]).Extension == ".zip" then
    To:
    Code:
    tbExt = String.SplitPath(tbFiles);
    if tbExt.Extension == ".zip" then;

  6. #6
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    Try this for the loop instead.

    Code:
    --stop the listbox from updating
    ListBox.SetUpdate("DirList", false);
    
    -- empty the listbox
    ListBox.DeleteItem("DirList",LB_ALLITEMS);
    
    tbFiles = FTP.ListFiles();
    
    -- can disconnect here (unless the FTP connection is needed for something else later)
    FTP.Disconnect();
    
    for numIndex, tblInfo in tbFiles do
    	if tblInfo then
    		local tbPath = String.SplitPath(tblInfo.Name);
    		if (tbPath) and (tbPath.Extension == ".zip") then
    			ListBox.AddItem("DirList", tblInfo.Name);
    		end
    	end
    end
    
    --allow the listbox to update
    ListBox.SetUpdate("DirList", true);
    • Do you really want to call FTP.Disconnect() each time through the loop? I would disconnect right after calling FTP.ListFiles (assuming you don't need the FTP connection for anything else later).
    • You don't need to call FTP.ListFiles() twice.
    • Use code tags when posting script, it preserves the indentation and makes it easier to read.
    --[[ Indigo Rose Software Developer ]]

  7. #7
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    Quote Originally Posted by mindstitchdr View Post
    Try changing:
    Code:
    if String.SplitPath(tbFiles[numIndex]["Name"]).Extension == ".zip" then
    To:
    Code:
    tbExt = String.SplitPath(tbFiles);
    if tbExt.Extension == ".zip" then;
    No. tbFiles contains numerically indexed subtables, it doesn't contain a path string.
    --[[ Indigo Rose Software Developer ]]

  8. #8
    Join Date
    Dec 2004
    Location
    Texas
    Posts
    239
    Sorry just trying to help.
    Last edited by mindstitchdr; 10-17-2007 at 03:08 PM.

  9. #9
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    Quote Originally Posted by mindstitchdr View Post
    Sorry just trying to help.
    That's okay! I just wanted to point it out since both you and arb suggested the same thing. It's a pretty easy mistake to make when reading code like that.
    --[[ Indigo Rose Software Developer ]]

  10. #10
    Join Date
    Jul 2007
    Posts
    158
    if String.Right(tbFiles[numIndex].Name, 3) == "zip" then
    AAAAAAAAH, that was stupid, I forgot what i had in mind

    if String.Right(tbFiles.Name, 3) == "zip" then

    Is that true?

  11. #11
    Join Date
    May 2005
    Posts
    1,115
    I would use it like this:

    if String.Lower(String.Right(tbFiles[numIndex].Name, 3)) == "zip" then
    Never know what life is gonna throw at you.
    (Based on a true story.)

  12. #12
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    Quote Originally Posted by arb View Post
    AAAAAAAAH, that was stupid, I forgot what i had in mind

    if String.Right(tbFiles.Name, 3) == "zip" then

    Is that true?
    Ah, sorry arb I misremembered your post, you were right the first time -- I forgot you had the [numIndex] accessor in there.

    tbFiles.Name won't work, because there is no "Name" element in the tbFiles table. The Name element is in one of the subtables inside the tbFiles table. So it's tbFiles[numIndex].Name, assuming numIndex is in range.

    But there's no need to use tbFiles at all if you're using a for loop to get each key/value pair in tbFiles.

    Code:
    for numIndex, tblInfo in tbFiles do
        -- at this point, tblInfo is the same as tbFiles[numIndex]
    end
    
    -- same thing with different variable names:
    for k, v in tbFiles do
        -- at this point, v is the same as tbFiles[k]
    end
    --[[ Indigo Rose Software Developer ]]

  13. #13
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Quote Originally Posted by Lorne View Post
    Try this for the loop instead.

    Code:
    --stop the listbox from updating
    ListBox.SetUpdate("DirList", false);
    
    -- empty the listbox
    ListBox.DeleteItem("DirList",LB_ALLITEMS);
    
    tbFiles = FTP.ListFiles();
    
    -- can disconnect here (unless the FTP connection is needed for something else later)
    FTP.Disconnect();
    
    for numIndex, tblInfo in tbFiles do
    	if tblInfo then
    		local tbPath = String.SplitPath(tblInfo.Name);
    		if (tbPath) and (tbPath.Extension == ".zip") then
    			ListBox.AddItem("DirList", tblInfo.Name);
    		end
    	end
    end
    
    --allow the listbox to update
    ListBox.SetUpdate("DirList", true);
    • Do you really want to call FTP.Disconnect() each time through the loop? I would disconnect right after calling FTP.ListFiles (assuming you don't need the FTP connection for anything else later).
    • You don't need to call FTP.ListFiles() twice.
    • Use code tags when posting script, it preserves the indentation and makes it easier to read.
    Unfortunently I still get the same ERROR... But thank you Lorne

  14. #14
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    Quote Originally Posted by Bruce View Post
    Unfortunently I still get the same ERROR... But thank you Lorne
    What line causes the error now?
    --[[ Indigo Rose Software Developer ]]

  15. #15
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    The same bugger!
    if String.SplitPath(tbFiles[numIndex]["Name"]).Extension == ".zip" then

Page 1 of 2 1 2 LastLast

Posting Permissions

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