Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 7 of 7

Thread: Table insertion

  1. #1
    Join Date
    Oct 2003
    Location
    West Monroe, LA
    Posts
    294

    Table insertion

    If I have two tables Table1 and Table2, how can I insert one item of Table2 into Table1 after every 4 items

    T1 T2
    1 A
    2 B
    3 C
    4 D
    ... ...
    New Table1
    1
    2
    3
    4
    A
    ...


    Mark

  2. #2
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Someone will probably come up with a more stream-lined way of doing this, but for a quick down and dirty, this should work.

    Code:
    --Initiate tables
    tblNum={"1","2","3","4"}
    tblAlph={"A","B","C","D"}
    
    --Initiate base variables
    blnDone = false
    nInsertPos = 5
    nCtr = 0
    
    --loop until we say we're done
    while blnDone == false do
    	if Table.Count(tblNum) >= (nInsertPos -1) then
    		nCtr = nCtr + 1
    		if Table.Count(tblAlph) >= nCtr then
    			Table.Insert(tblNum, nInsertPos, tblAlph[nCtr])
    			nInsertPos = nInsertPos + 5
    		else
    			blnDone = true
    		end
    	else
    		blnDone = true
    	end
    end
    Last edited by Worm; 08-18-2004 at 08:44 AM.

  3. #3
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    This should work as well, not quick enough on the draw (code) to beat work. Need more coffee.
    Code:
    --initialize tables
    --table 1
    table1 = {};
    for x = 1,20 do
    	Table.Insert(table1, x, x);
    end
    
    t1display = ""
    for y = 1,Table.Count(table1) do
    	t1display = t1display .." ".. table1[y]
    end
    
    Dialog.Message("Table1", t1display)
    
    --table two this uses the ascii decimal values to for A-E
    table2 = {};
    for x = 65,69 do
    	Table.Insert(table2, x - 64, String.Char(x));
    end
    
    t2display = "";
    for t2i, t2v in table2 do
    	t2display = t2display .." ".. t2v;
    end
    
    Dialog.Message("Table2", t2display);
    
    --Check that the tables exist.
    if table1 and table2 then
    	--create a new table and copy the contents from the table1 to the new table
    	newtable = {};
    	for index,value in table1 do
    		Table.Insert(newtable, index, value);
    	end
    
    	--This is what inserts the contents of table2 into the fourth position in the newtable.
    	for i,v in table2 do
    		Table.Insert(newtable, (4*i)+i, v)
    	end
    
    	--display for the new table
    	tndisplay = "";
    	for tni, tnv in newtable do
    	tndisplay = tndisplay .." ".. tnv;
    end
    
    Dialog.Message("NewTable", tndisplay);
    else
    	Dialog.Message("Notice", "Your tables are not complete.  Click the two table buttons to create those tables first");
    end
    After posting this looks like a lot of code, the code that inserts your information from table two into the new table is this code:
    Code:
    for i,v in table2 do
    	Table.Insert(newtable, (4*i)+i, v)
    end
    I hope that helps.
    Last edited by TJ_Tigger; 08-18-2004 at 09:20 AM.
    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

  4. #4
    Join Date
    Oct 2003
    Location
    West Monroe, LA
    Posts
    294
    Thats just what I was looking for.

    If I create a table from one listbox and a second from another listbox how can I use the example above to fill in the third listbox with the combined data?

  5. #5
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    after you get the table set to the values you want, then do something like this.

    Code:
    --clear the listbox
    ListBox.DeleteItem("Listbox3", LB_ALLITEMS)
    
    --add the elements from the table to the listbox
    for n, Table.Count(tblNum) do
    	ListBox.AddItem("Listbox3", tblNum[n])
    end
    Quote Originally Posted by markstaylor
    Thats just what I was looking for.

    If I create a table from one listbox and a second from another listbox how can I use the example above to fill in the third listbox with the combined data?

  6. #6
    Join Date
    Oct 2003
    Location
    West Monroe, LA
    Posts
    294
    When I use that example I get compiling error so I changed it to
    for n, v in newtable do
    ListBox.AddItem("Listbox1", newtable[n]);
    end

    But I get a "Argument 2 must be of type String" error

  7. #7
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Sorry, I typed that one out. There I go thinking I had the syntax down when I didn't. I didn't have n=1 in the for statement


    Code:
    --clear the listbox
    ListBox.DeleteItem("Listbox3", LB_ALLITEMS)
    
    --add the elements from the table to the listbox
    for n=1, Table.Count(tblNum) do
    	ListBox.AddItem("Listbox3", tblNum[n])
    end

Similar Threads

  1. CSV file content to a table into AMS5. Is it possible?
    By Martin_SBT in forum AutoPlay Media Studio 5.0
    Replies: 18
    Last Post: 11-21-2005, 12:42 AM
  2. Email Input Text ??
    By octane6228 in forum AutoPlay Media Studio 5.0
    Replies: 25
    Last Post: 02-21-2004, 03:59 PM
  3. Incrementing a table name
    By arnaud in forum AutoPlay Media Studio 5.0
    Replies: 4
    Last Post: 01-13-2004, 05:36 PM
  4. Creating a Table of Contents
    By Desmond in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 10-03-2003, 11:35 AM

Posting Permissions

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