0

Say I have a CE Lua form and some variables:

form.Show()
list = form.CEListView1

tab_player = {}

p_name = 'Joe'
p_gen = 'Male'

table.insert(tab_player,{player_name = p_name, player_gen = p_gen})

-- and then add some elements from List View to same record index

for idx = list.ItemIndex + 1, list.Items.Count-1 do
 mtrl_name = list.Items[idx].Caption
 mtrl_qty =  list.Items[idx].SubItems[0]
 mtrl_unit = list.Items[idx].SubItems[1]
 mtrl_price = list.Items[idx].SubItems[2]
 mtrl_tprice = list.Items[idx].SubItems[3]
 table.insert(tab_player, {v_itemname = mtrl_name, v_itemqty = mtrl_qty,
              v_itemunit = mtrl_unit, v_itemprice = mtrl_price, v_itemttlprice = mtrl_tprice})
end

-- check
for index, data in ipairs(tab_player) do
    print(index)
    for key, value in pairs(data) do
        print('\t', key, value)
    end
end

Result, it's created 9 tab_player record indexes (depending how many items on list view). What I want is like this structure for one record index:

tab_player = 
{
  player_name = p_name,
  player_gen = p_gen,

  {
    v_itemname = mtrl_name,
    v_itemqty = mtrl_qty,
    v_itemunit = mtrl_unit,
    v_itemprice = mtrl_price,
    v_itemttlprice = mtrl_tprice},

   {
    v_itemname = mtrl_name,
    v_itemqty = mtrl_qty,
    v_itemunit = mtrl_unit,
    v_itemprice = mtrl_price,
    v_itemttlprice = mtrl_tprice},

  {
    v_itemname = mtrl_name,
    v_itemqty = mtrl_qty,
    v_itemunit = mtrl_unit,
    v_itemprice = mtrl_price,
    v_itemttlprice = mtrl_tprice}

    -- and so on
} 
  1. How CE Lua script to get the structure as I want?

  2. If done, then how CE Lua script call the data from tab_player to fill player name editbox, player gen editbox and fill the items to CE List View?

EDIT: What I want to be produce an array table with structure below:

list = UDF1.CEListView1

tab_player = {}

player_name = 'Joe'
player_gen = 'Male'

-- this is list view items contain:

--- row 1, column 1 to 5
mtrl_name = list.Items[1].Caption   -- Milk
mtrl_qty =  list.Items[1].SubItems[0]  -- 300
mtrl_unit = list.Items[1].SubItems[1]  -- ml
mtrl_price = list.Items[1].SubItems[2] -- 3975
mtrl_tprice = list.Items[1].SubItems[3] -- 3975

--- row 2, column 1 to 5
mtrl_name = list.Items[2].Caption   -- Sugar
mtrl_qty =  list.Items[2].SubItems[0]  -- 1
mtrl_unit = list.Items[2].SubItems[1]  -- Kg
mtrl_price = list.Items[2].SubItems[2] -- 18000
mtrl_tprice = list.Items[2].SubItems[3] -- 18000

--- row 3, column 1 to 5 and so om

the tab_player should be:

tab_player = {

-- index 0 or record 1
{player_name = 'Joe', player_gen = 'Male',

-- row 1, column 1 to 5
  {
   item_name = 'Milk',
   item_qty = 300,
   item_unit = 'ml',
   item_price = 3975,
   item_tprice = 3975
  },

-- row 2, column 1 to 5
  {
   item_name = 'Sugar',
   item_qty = 2,
   item_unit = 'Kg',
   item_price = 9000
   item_tprice = 18000
  },

-- row 3, column 1 to 5
  {
   item_name = 'bla bla bla',
   item_qty = 1,
   item_unit = 'bla',
   item_price = 1000000
   item_tprice = 1000000
  }

-- and so on
}

How to create, print multidimensional and call back the item from the array table as above?.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JoeFern
  • 117
  • 1
  • 8

0 Answers0