PDA

View Full Version : Having a Table moment! Please help!!!...


danward79
January 30th, 2005, 01:34 PM
Hi,

I have the following table. Which is giving me some trouble!

LightTimers = {}
LightTimers.Timer = {}

LightTimers.Timer[1] = {timerday = "Weekdays", timertime = "17:30", timertriggerevent = "X10.LightsOn", timertriggereventid = "18", timertriggerpld1 = pld1, timertriggerpld2 = "4", timerenabled = "Enabled"}
LightTimers.Timer[2] = {timerday = "Weekdays", timertime = "21:30", timertriggerevent = "X10.LightsOff", timertriggereventid = "18", timertriggerpld1 = pld1, timertriggerpld2 = "4", timerenabled = "Enabled"}
LightTimers.Timer[3] = {timerday = "Weekends", timertime = "12:00", timertriggerevent = "X10.LightsOn", timertriggereventid = "18", timertriggerpld1 = pld1, timertriggerpld2 = "4", timerenabled = "Enabled"}


This will return the number of elements in the table

getn(LightTimers.Timer)

but I want to return the number of elements in Timer, however, this does not work, it returns 0 see below

getn(LightTimers.Timer[1])

I would expect it to return 7, so how can I do it, I know I am just being stupid!

Please enlighten me :oops:

Rob H
January 30th, 2005, 02:54 PM
I think that the problem is to do with the way that getn() works. It looks for an attribute 'n' which is created by use of tinsert() and a couple of other ways. I'm guessing that it doesn't happen if you create a table using a table constructor.

Why do you need to use getn()?

danward79
January 30th, 2005, 03:01 PM
dunno!

I think I have found the answer now!

for i, v in LightTimers.Timer do
for i, x in v do
print (i," ",x)
end
print ("---------------")
end