Create tables

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

Create tables

Post by sashapont »

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: 349
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

Re: Create tables

Post by Clyde »

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 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: Create tables

Post by sashapont »

Is not work!

Table menuitiem{} not found!
SamuraiCrow
Posts: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Create tables

Post by SamuraiCrow »

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
I'm on registered MorphOS using FlowStudio.
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: Create tables

Post by sashapont »

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: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Create tables

Post by SamuraiCrow »

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'm on registered MorphOS using FlowStudio.
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: Create tables

Post by sashapont »

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: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: Create tables

Post by Bugala »

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: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Create tables

Post by SamuraiCrow »

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.
I'm on registered MorphOS using FlowStudio.
Post Reply