Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2007
    Location
    Mar Sara
    Posts
    292

    Trying to find a bug in my code

    I'm creating a database written in a XML file. Now I'm testing what I've done so far, and I get a "table index is nil" error in the following function.

    I can't seem to find the error in it, can someone help, please? Here's the code:

    Code:
    function xdbOpenDB(strXdbPath)
    	-- if there's no database open
    	if tblXDB == nil then
    		-- set the number of open databases to zero
    		local numOpenXDBs = 0;
    
    		-- create the database table
    		tblXDB = {};
    
    		-- set the index of the database
    		local numXdbHandle = 1;
    	else
    		-- count the number of open databases
    		local numOpenXDBs = Table.Count(tblXDB);
    
    		-- if the number of open databases is zero
    		if numOpenXDBs == 0 then
    			-- create the database table
    			tblXDB = {};
    		end
    
    		-- set the index of the database
    		local numXdbHandle = numOpenXDBs + 1;
    	end
    
    	-- add the database path to the table
    	tblXDB[numXdbHandle] = strXdbPath;
    
    	-- return the database index
    	return numXdbHandle;
    end
    I attached the project.
    Attached Files

  2. #2
    Join Date
    Apr 2007
    Location
    Mar Sara
    Posts
    292
    I updated the function, but still the same error, the table doesn't get any item:

    Code:
    function xdbOpenDB(strXdbPath)
    	-- if there's no database open
    	if tblXDB == nil then
    		-- set the number of open databases to zero
    		local numOpenXDBs = 0;
    
    		-- create the database table
    		tblXDB = {};
    
    		-- set the index of the database
    		local numXdbHandle = 1;
    	else
    		-- count the number of open databases
    		local numOpenXDBs = Table.Count(tblXDB);
    
    		-- if the number of open databases is zero
    		if numOpenXDBs == 0 then
    			-- create the database table
    			tblXDB = {};
    
    			-- set the index of the database
    			local numXdbHandle = 1;
    		else
    			-- set the index of the database
    			local numXdbHandle = numOpenXDBs + 1;
    		end
    	end
    
    	-- add the database path to the table
    	Table.Insert(tblXDB, numXdbHandle, strXdbPath);
    
    	-- return the database index
    	return numXdbHandle;
    end

  3. #3
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    Remove the local from local numXdbHandle = 1 and local numXdbHandle = numOpenXDBs + 1

    When you use local inside an if statement, the variable will not be available outside the if statement.
    Dermot

    I am so out of here

  4. #4
    Join Date
    Apr 2007
    Location
    Mar Sara
    Posts
    292
    Thank you! I should have declarde it as local at the beginning of the function...

Similar Threads

  1. Article: Using Authenticode Code Signing Certificates
    By Ted Sullivan in forum Setup Factory 8.0 Examples
    Replies: 4
    Last Post: 10-31-2007, 09:03 AM
  2. TrueUpdate 2.0 Update (v2.0.6.0) Released
    By Brett in forum TrueUpdate 2.0
    Replies: 0
    Last Post: 10-31-2006, 01:10 PM

Posting Permissions

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