btpoole
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2014
07:03 AM
Multi Dimensional Array
Not sure if I am doing this right. I am creating a multidimensional array like:
This works to populate the arrary but not exactly. If I ?videoinfo.vid , videoinfo.vtitle, videoinfo.vdate or videoinfo.vtime I get the entire list each. I need to extract or print a single instance for example:
If I have the following and push it to the array videoinfo along with 10 other groups like the one below.
videoid= 5
videotitle="My Video"
Videodate= 12/01/14
videotime= 1:00
Now I only want the first group in the array so,
?videoinfo[0].vid
?videoinfo[0].vtitle
?videoinfo[0].vdate
?video[0].vtime
or change the index to any number to print or extract that group. When I try to print using an idex I get a type mismatch.
Thanks
Videoinfo={
vid: videoid,
vtitle: videotitle,
vdate: videodate,
vtime: videotime
}
This works to populate the arrary but not exactly. If I ?videoinfo.vid , videoinfo.vtitle, videoinfo.vdate or videoinfo.vtime I get the entire list each. I need to extract or print a single instance for example:
If I have the following and push it to the array videoinfo along with 10 other groups like the one below.
videoid= 5
videotitle="My Video"
Videodate= 12/01/14
videotime= 1:00
Now I only want the first group in the array so,
?videoinfo[0].vid
?videoinfo[0].vtitle
?videoinfo[0].vdate
?video[0].vtime
or change the index to any number to print or extract that group. When I try to print using an idex I get a type mismatch.
Thanks
2 REPLIES 2

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2014
07:49 AM
Re: Multi Dimensional Array
I may not be understanding completely, but it sounds like what you want isn't a multidimensional array (an array of arrays), but rather an array of Associative Arrays.
--Mark
videoinfo = []
video1 = {
vid: videoid,
vtitle: videotitle,
vdate: videodate,
vtime: videotime
}
videoinfo.Push(video1)
video2 = ...
videoinfo.Push(video2)
... etc
print videoinfo[0].vtitle
print videoinfo[1].vtitle
--Mark
btpoole
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2014
06:25 PM
Re: Multi Dimensional Array
Mark
Thanks for the help on this. I have done as suggested and works great but it leads to a problem. I was under impression that once an array was created, its value remained set until changed. What I mean is the following. Within a function I have several conditional statments. In the first m.xmlexist=0, the code will run when the channel loads, executes correctly and sets m.xmlexist=1, so the next conditional statement will run directly after the initial. All this works perfect. After the channel has loaded and the roArray programlist has been created nothing changes the value of programlist array. When a selection is made with the remote, a function is called that sets the value of m.xmlexit=2. The function is called, the m.xmlexist=0 and =1 is passed over, the execution enters the third conditional statment correclty but the roArray programlist.count() throws a Dot operator error as if the programlist roarray has not been established. The roArray was created in the second conditional statment and shows to be populated. Once the code proceeds thru the function the first time, is the value of the roArray "forgotten"? I thought once it was established I could call it back within the same function and it retain value. I maybe really missing something. From database programming I was seeing the roArray created was kinda like a recordset that was created from xml file. I was doing it like this so the complete xml file didn't have to parsed each time a selection was made, only the roArray programlist. Thanks for any advice
Thanks for the help on this. I have done as suggested and works great but it leads to a problem. I was under impression that once an array was created, its value remained set until changed. What I mean is the following. Within a function I have several conditional statments. In the first m.xmlexist=0, the code will run when the channel loads, executes correctly and sets m.xmlexist=1, so the next conditional statement will run directly after the initial. All this works perfect. After the channel has loaded and the roArray programlist has been created nothing changes the value of programlist array. When a selection is made with the remote, a function is called that sets the value of m.xmlexit=2. The function is called, the m.xmlexist=0 and =1 is passed over, the execution enters the third conditional statment correclty but the roArray programlist.count() throws a Dot operator error as if the programlist roarray has not been established. The roArray was created in the second conditional statment and shows to be populated. Once the code proceeds thru the function the first time, is the value of the roArray "forgotten"? I thought once it was established I could call it back within the same function and it retain value. I maybe really missing something. From database programming I was seeing the roArray created was kinda like a recordset that was created from xml file. I was doing it like this so the complete xml file didn't have to parsed each time a selection was made, only the roArray programlist. Thanks for any advice
If m.xmlexist=0
procedure carried out
m.xmlexist=1
End if
If m.xmlexist=1
programlist=[]
programinfo=[]
For i= 0 to xml.programme.count()-1
programinfo={
date: xml.programme[i]@start,
time: xml.programme[i]@start,
title: xml.programme[i].title.gettext()
channel: xml.programme[i]@channel 'GET CHANNEL
}
?"SHOW DATE. .."programinfo.date
?"SHOW TIME. . ."programinfo.time
?"SHOW TITLE. . ."programinfo.title
?"SHOW CHANNEL. . ."programinfo.channel
programlist.Push(programinfo)
End For
?"PROGRAMLIST CREATED. . ."
?"PROGRAMLIST COUNT. . ."programlist.count()
End if
If m.xmlexist=2
?"PROGRAMLIST COUNT. . ."programlist.count()
End if