Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2007
    Location
    London, UK
    Posts
    19

    How to use nested tables

    hi,I'm working on an app at the moment that is bringing in database data. To use that data in MS I want to convert the raw table into a nested table. Ideally, this would be a 3 level deep nested table (array) with various types of info stored in it. Some info would just need the 1 or 2 levels, whilst others would need all 3. i.e.

    order[1][1][1]

    would store...

    order.items.item1.item Name

    or

    order.items.item2.item2 quantity

    or

    order.InvoiceNumber

    or

    order.deliveryType

    Problem is... I can't grasp from the docs how you exactly create a dynamic nested array of this kind. Is this even possible? In other scripting languages I would expect to define the original array (order[][][]), and then to be freely able to add values to it ad-hoc, and for the table to adjust as needed. But what I actually find is that assigning say...

    order[1][1] = "funky";

    works. Whilst..

    order[13][1] = "bummer";

    does not....

    If nested tables in LUA are not dynamic, it looks like I'll just have to forget the whole nested system and go for a much flatter (and harder to code model).

    And guidance appreciated here. Does anyone have any extensive examples of how to create and work with nested arrays? Can they be fully dynamic i.e. can I simply assign values to any level of the nest and LUA will create the tables as needed on the fly?

    Cheers

    Chris

  2. #2
    Join Date
    May 2006
    Posts
    1,443
    i never tried it out.
    just a suggestion.
    i don't know does it work.

    order = {sub1={},sub2={},sub3={}};

    order.sub1[1] = "any";
    order.sub1[2] = "any2";

    order.sub2[1] = "any";
    order.sub2[2] = "any2";

    order.sub2[1] = "any";
    order.sub2[2] = "any2";

    Or

    order = {sub1={sub2={sub3={}}}};

    order[1].sub1[1].sub2[1].sub3[1] = "any";

  3. #3
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Yeah that can be a tricky subject to start working with. Once you have it you will be able to work with it relatively easy. One thing that might help in seeing how nested tables work is to look at the SQLite.QueryToTable function and see how it returns information and how you can access the different points of data.

    You can define a table with the following code

    mytable = {};

    Now that you have a table you can then populate that table with strings, numbers, tables, functions and all sorts of stuff. So how do we do this?

    Once your table is created you can then populate it with the following.

    mytable.version = "1.0.0.1";

    This adds an entry to the table called 'version' that would return 1.0.0.1 when called.

    Dialog.Message("table info", mytable.version);

    Defining a table within a table is just like defining a table.

    mytable.nestedtable = {};

    Now the value of mytable.nestedtable is a table. You could use a for loop to dynamically populate it as well

    for n = 1,10 do
    mytable.nestedtable[n] = "value"..n;
    end

    And you could then read out the table like this

    for index, value in mytable.nestedtable do
    Dialog.Message(index,value);
    end

    or you could return a specific value like this

    Dialog.Message("number 4", mytable.nestedtable.4);

    or

    Dialog.Message("number 4", mytable.nestedtable[4]);

    If your array uses a named field make sure to quote the named field within the square brackets.

    mytable.nestedtable.namedvalue = "mysoftware"

    Dialog.Message("My softwares name", mytable.nestedtable["namedvalue"]);

    Hopefully that will help to get you started anyway. My disclaimer on the above code is as follows. I didn't type it in AMS so I was pulling it off the top of my head. Hopefully it will work if you were to cut and paste but I might have spelling errors or syntatical errors. But hopefully it will help you learn the ropes.

    Tigg
    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
    Mar 2007
    Location
    London, UK
    Posts
    19
    Thanks for the run through Tiggs. I now have a working system in place, it does not use nested tables to the degree I had planned. But I have used them to a smaller degree.

    Cheers

    CT

Similar Threads

  1. creating dynamic tables inside tables...
    By Jonas DK in forum AutoPlay Media Studio 6.0
    Replies: 24
    Last Post: 04-25-2007, 09:56 AM
  2. Always confusing with tables
    By arnaud in forum AutoPlay Media Studio 5.0
    Replies: 3
    Last Post: 01-25-2004, 06:33 PM
  3. Working with Tables and Files
    By Desmond in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 12-23-2003, 08:22 AM
  4. HOWTO: Create Nested Shortcuts in the Start Menu
    By Support in forum Setup Factory 6.0 Knowledge Base
    Replies: 0
    Last Post: 09-24-2002, 10:26 AM
  5. How do you remove a nested folder?
    By Toby123 in forum Setup Factory 6.0
    Replies: 2
    Last Post: 07-31-2002, 06:42 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