Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2007
    Posts
    4

    tables are not simple! or are they?

    Greetings to all,

    Maybe I'm overlooking the obvious here but I can't manage to do something which I think I should be able to do with tables. I'm newby so please forgive my naivety. I've the following table:

    tab_def={}
    emp01={name="Carlos Freeman", dob="23/12/74", jobTitle="dispatch rider", hobbies="mountain claiming"};
    tab_def[emp01]=emp01;
    emp02={name="Emma Dobson", dob="02/02/68", jobTitle="dispatch rider", hobbies="cycling"};
    tab_def[emp02]=emp02;
    emp03={name="Katia Korsacova", dob="04/07/69", jobTitle="post room", hobbies="reading"};
    tab_def[emp03]=emp03;

    which I add to a listbox:

    for k in tab_def do
    ListBox.AddItem("list_peo", tab_def[k].name);
    end


    I would like to be able to select one person from the list and display all info in a single paragraph. All I manage is to dislay the name.

    result = ListBox.GetSelected("list_peo");
    which_name = ListBox.GetItemText("list_peo", result[1]);

    Paragraph.SetText("list_det", which_name);

    How can I move forward with this? I'd be grateful for any help.

    antonio

  2. #2
    Join Date
    May 2005
    Posts
    1,115
    Do the list adding like this:

    Code:
    for index,item in tab_def do
    ListBox.AddItem("list_peo", item.name);
    end
    Last edited by bule; 06-14-2007 at 09:46 AM.
    Never know what life is gonna throw at you.
    (Based on a true story.)

  3. #3
    Join Date
    May 2005
    Posts
    1,115

    Wink

    To display details:

    Code:
    result = ListBox.GetSelected("list_peo");
    which_name = ListBox.GetItemText("list_peo", result[1]);
    for index,item in tab_def do
    if item.name=which_name then
    details=item.name.."\r\n"..item.dob.."\r\n"..item.jobTitle.."\r\n"..item.hobbies
    break
    end
    
    Paragraph.SetText("list_det", details);
    There are other ways to do it better but this will give you a general idea.
    Never know what life is gonna throw at you.
    (Based on a true story.)

  4. #4
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    I'd do a table of tables. Put the details into a table, and assign that to the main table using the name as the key. Then you don't have to loop to look up the data, just retrieve it associatively.

    Example:
    Code:
    -- set up the employee tables
    tbEmployees={};
    tbEmployees["Carlos Freeman"] = {dob="23/12/74", jobTitle="dispatch rider", hobbies="mountain claiming"};
    tbEmployees["Emma Dobson"] = {dob="02/02/68", jobTitle="dispatch rider", hobbies="cycling"};
    tbEmployees["Katia Korsacova"] = {dob="04/07/69", jobTitle="post room", hobbies="reading"};
    
    -- empty the list box
    ListBox.DeleteItem("list_peo", LB_ALLITEMS);
    
    -- add the employee names to the list box
    for name,tbDetails in tbEmployees do
        ListBox.AddItem("list_peo", name);
    end
    
    -- display the selected employee's information in a paragraph object
    -- (put this in the list box object's On Select event)
    tbSelected = ListBox.GetSelected("list_peo");
    if tbSelected then
    	name = ListBox.GetItemText("list_peo", tbSelected[1]);
    	tbDetails = tbEmployees[name];
    	if tbDetails then
    		Paragraph.SetText("list_det", name.."\r\n"..tbDetails.dob.."\r\n"..tbDetails.jobTitle.."\r\n"..tbDetails.hobbies);
    	end
    end
    --[[ Indigo Rose Software Developer ]]

  5. #5
    Join Date
    Mar 2007
    Posts
    4

    tables are simple affairs after all

    ...but only after someone else shows you how to do it. Joking aside it is very encouraging to be put on the right track within a very short space of time.

    Thank you Bule and Lorne.

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. Do AMS can do Simple DVD Videos........?
    By DaSoul in forum AutoPlay Media Studio 6.0
    Replies: 3
    Last Post: 04-23-2007, 12:48 AM
  3. Simple Print Paragraph?
    By publishers in forum AutoPlay Media Studio 5.0
    Replies: 4
    Last Post: 03-28-2005, 06:24 PM
  4. Always confusing with tables
    By arnaud in forum AutoPlay Media Studio 5.0
    Replies: 3
    Last Post: 01-25-2004, 06:33 PM
  5. 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

Posting Permissions

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