I am working on formatting an xml string from table data to generate an animated Toolbox to use as a global stand alone custom toolbar. I am using the xbasic from the Action Script for my model. I have found a couple of good posts on creating the xml but no one was trying to make one of these where grouping categories and their items like a tree is needed.
In my script, I first created an array of the categories using a unique index from the table. I want to test this value as I loop thru the table getting the items and when another unique category value is encountered, create a new category xml tag. But I am getting an 'array out of bounds' error when I try to compare a variable with the array[i] value.
My first question about this error: Is it 'ok' to open a table once, set a primary index, fetch thru the table to get the array and then change the primary index and fetch thru the same table again? Or is it better to close the table and reopen it?
This is the part of the function that works fine:
But this next section throws the error:
all the variables are dimmed and set to default values
In my script, I first created an array of the categories using a unique index from the table. I want to test this value as I loop thru the table getting the items and when another unique category value is encountered, create a new category xml tag. But I am getting an 'array out of bounds' error when I try to compare a variable with the array[i] value.
My first question about this error: Is it 'ok' to open a table once, set a primary index, fetch thru the table to get the array and then change the primary index and fetch thru the same table again? Or is it better to close the table and reopen it?
This is the part of the function that works fine:
Code:
GETCATS: tbl = table.open("act_menu") on error goto CLOSEIT idx = tbl.index_primary_put("Grp1_U") 'grp2_u crecs = idx.records_get() dim cats[crecs] as c tbl.fetch_first() while .not. tbl.fetch_eof() i=i+1 cats[i] = alltrim(tbl.menu_grp1) 'tbl.menu_grp2 tbl.fetch_next() end while 'TESTARRAY: 'to test the category array - comment out lines following GETITEMS 'tbl.close() 'lst=ui_get_list_array("",1,"cats") 'get_menu = lst
Code:
GETITEMS: i = 1 idx = tbl.index_primary_put("SORTKEY") irecs = idx.records_get() tbl.fetch_first() 'set the first category catnm = alltrim(tbl.menu_grp1) 'tbl.menu_grp2 lst = "<<%xml%"+crlf()+"<toolbox animate=\"true\" type=\"List\" theme=\"NATIVEWINXP\" >"+crlf() lst = lst+"<category name="+quote(cats[i])+"state="+quote(catstate)+" >"+crlf() 'only first category is open all others will be closed catstate = "Closed" while .not. tbl.fetch_eof() [COLOR=#ff0000]if catnm <> cats[i] then [/COLOR] lst = lst+"< /category>"+crlf() 'only add a new category line if unique lst = "<category name="+quote(cats[i])+"state="+quote(catstate)+" >"+crlf() catnm = cats[i] end if imgno = val(tbl.xmlimg) lst = lst+"<item text="+quote()tbl.menu_grp2)+" icon="+quote(imgs[imgno])+" data="+quote(tbl.obj_name)+" onclick="+quote(tbl.sortkey)+" />"+crlf() i = i+1 tbl.fetch_next() end while
Comment