Create tables

Discuss any general programming issues here
Post Reply
sashapont
Posts: 131
Joined: Thu Aug 03, 2017 2:49 pm

Create tables

Post by sashapont » Wed Oct 02, 2019 11:10 am

I want to create many table in runtime I don't know how mucky it will be at the program start. How I can do it in for next like?

Code: Select all

 For t = 1 to c
MenuItiem..[t]..$={}
 Next


User avatar
Clyde
Posts: 198
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

Re: Create tables

Post by Clyde » Wed Oct 02, 2019 2:01 pm

To create the table at runtime you would do something like:

Code: Select all

For t = 1 to c
    MenuItiem[t] = yourDynamicValue
Next
Currently using: Hollywood 8 with Windows IDE

sashapont
Posts: 131
Joined: Thu Aug 03, 2017 2:49 pm

Re: Create tables

Post by sashapont » Wed Oct 02, 2019 7:37 pm

Is not work!

Table menuitiem{} not found!

SamuraiCrow
Posts: 242
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: Create tables

Post by SamuraiCrow » Wed Oct 02, 2019 9:05 pm

Let's try again. You are trying to generate names dynamically? If so it needs to be inside an outer table.

Code: Select all

MenuItem={}
For t=0 to c
  MenuItem[t]={}
Next

sashapont
Posts: 131
Joined: Thu Aug 03, 2017 2:49 pm

Re: Create tables

Post by sashapont » Wed Oct 02, 2019 9:12 pm

SamuraiCrow wrote:
Wed Oct 02, 2019 9:05 pm
Let's try again. You are trying to generate names dynamically? If so it needs to be inside an outer table.

Code: Select all

MenuItem={}
For t=0 to c
  MenuItem[t]={}
Next
No I want many tables for example I want:

MenuItiem1$={1,2,3..}
MenuItiem2$={1,2,3...}
MenuItiem3$={1,2,3...}

...
MenuItiem100$={1,2,3...}

SamuraiCrow
Posts: 242
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: Create tables

Post by SamuraiCrow » Wed Oct 02, 2019 9:19 pm

You still need to put those 100 tables in an outer one. You can use a string concatination to generate a key value. Local and Global variables cannot use dynamic names.

Code: Select all

Global tbl={}
For t=0 to c
  tbl["MenuItem"..StrStr(t).."$"]={}
Next

sashapont
Posts: 131
Joined: Thu Aug 03, 2017 2:49 pm

Re: Create tables

Post by sashapont » Wed Oct 02, 2019 9:32 pm

SamuraiCrow wrote:
Wed Oct 02, 2019 9:19 pm
You still need to put those 100 tables in an outer one. You can use a string concatination to generate a key value. Local and Global variables cannot use dynamic names.

Code: Select all

Global tbl={}
For t=0 to c
  tbl["MenuItem"..StrStr(t).."$"]={}
Next
I don't understand clearly....

I use this code and than
SystemRequest("tbl", ListItems(tbl), "OK",#REQICON_WARNING)
I have 0. Why not 100?

Bugala
Posts: 825
Joined: Sun Feb 14, 2010 7:11 pm

Re: Create tables

Post by Bugala » Wed Oct 02, 2019 10:58 pm

Actually it is possible to affect Global variables names in Hollywood since all variables are stored in table "_G":

Code: Select all

_G["test"] = 1
DebugPrint(test)
However, I do recommend sticking on multiple dimension table rather.

SamuraiCrow
Posts: 242
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: Create tables

Post by SamuraiCrow » Thu Oct 03, 2019 8:10 am

sashapont wrote:
Wed Oct 02, 2019 9:32 pm
I use this code and than
SystemRequest("tbl", ListItems(tbl), "OK",#REQICON_WARNING)
I have 0. Why not 100?
Use TableItems() instead of ListItems() because it isn't an array.

Post Reply