Page 1 of 1

Populating lists via scripts

Posted: Mon Sep 22, 2003 10:55 am
by kbosscawen
I've got something rather specific that I'm trying to do with HouseBot to expand the capabilities of the TV Listing device, but I'm not sure how to go about doing it. What I'd like to do is build a list that's similar to the TV Listing property but that contains only the shows that are on now. I feel comfortable about building and running the query that's needed, but I'm not sure how to use the results to populate a multiple column list in HB, and, furthermore, how I would display/use the multiple column list once it's populated. Any ideas?



Thanks.

Posted: Mon Sep 22, 2003 2:21 pm
by ScottBot
Great question, since it's completely undocumented :oops:



I've made a sample configuration so you have some actual examples of it being done. You can download it from here. You will need to import it with "File / Import Configuration...". It uses a VB Script to update the List Controls through two Alpha List Property Values.



Here are the details in writing:

List Controls display Alpha List Property Types. An Alpha List Property Value is really just a single string that is delimited with new line characters (\n) for each item in the list. When you select an item in the list, the text value of the selected item will be assigned to the property value assigned to the Change Property of the List Control.



For the TV Listing Device, I had to expand the functionality of the basic list control to allow for multiple columns and to assign data (an ID) to a list item that is not displayed. I also needed to add the ability to tell the list control which item to select after populating the list.



Here are the details for the enhancements.

To break a list item into multiple columns, delimit the item with tabs (\t). The first item in the list defines the number of tabs in the list, and all other items should have the same number of tabs. The first value in the tab delimited item is the item ID. The ID can be any value that you choose. This is the value that will be returned when the item is selected. The ID is not shown in the list.



For the list control to automatically select an item in the list (instead of the first item), prefix the item ID with *S- (I know that's weird).



That's it in a nutshell.



If you come up with something cool that can be shared with the rest of the community, let me know and I'll add it to the sample TV Listing Configuration.



Scott

Posted: Sat Oct 18, 2003 11:12 am
by kbosscawen
I finally got back to trying this...



The following code will give me what I need to populate the WhatsOnNow list (UserAlphaList1) that that I added to the TVListings device, but when I run it to populate WhatsOnNow, it abends HB. Through some trial and error, I've found that there seems to be a limit to the size you can assign to an AlphaList through a script device.


Code: Select all

Set dbConn = CreateObject( "ADODB.Connection" ) 

' Set path to MDB file in variable 
Dim pathToDB 
pathToDB = "\Program Files\HouseBot\Config\Listings.mdb" 

' Open connection to DB 
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pathToDB 

' Execute query for the Description of the System Time Device 
Set rs = dbConn.Execute( "SELECT Programs.ChannelNumber, Programs.ShortTitle, Programs.SubTitle, Programs.Description FROM Programs WHERE (((Programs.StartTime)<Now()) AND ((Programs.EndTime)>Now()))" ) 

' Populate list
szList = ""
SetPropertyValue "TVListings.WhatsOnNow",""
'while (not(rs.EOF)) 
'	szList = szList & rs("ChannelNumber") & chr(9) & rs("ChannelNumber") & chr(9) & rs("ShortTitle") & chr(9) & rs("Description") & chr(10)
'	rs.movenext
'wend

'Test for loop to find out how big the alphalist can be without abending HB
' I incremented the upper value of n until HB abended - 252 abends HB

for n = 1 to 251
	szList = szList & "+"
next

msgbox (szList)
SetPropertyValue "TVListings.WhatsOnNow",szList
I originally tried the WHILE loop to build the list I want to build, but it kept shutting down HB. I knew it was the SetPropertyValue that was shutting it down because szList would display in a msgbox. So.... I put the FOR loop in to see at what szList size the SetPropertyValue broke, and the magic size is 251.

I'm not a coding genius - Can you let me know what I'm doing wrong? Is there a limit to the size an AlphaList when setting its value through a script?

Thanks for your help.[/code]

Posted: Sat Oct 18, 2003 2:02 pm
by ScottBot
The maximum length of a Property Value for the system is 250 bytes long (as you have found out).



AlphaLists could probably be longer, since each item in the list should have a limit of 250 bytes. However, the current Plugin interface supports the 250 byte limit for all Property Values.



I've fixed HB so it will truncate the data instead of crashing. This will be in the next version, but it won't really help you.



Roughly, how big (how many bytes) are your needing to set the AlphaList value to?



Scott

Posted: Sat Oct 18, 2003 2:28 pm
by ScottBot
After digging a bit deeper into this, I have some good news to report. I think you will be OK with the next version. The reason is (if you want to hear the technical details)...



The Script Device is able to successfully send the large Property Value to HB without a problem. The crash occurred when the NULL Device attempted to retrieve the data from HB. Now that the crash is fixed (in the next version), the NULL Device no longer crashes and is able to retrieve only 250 bytes of the changed value. However, since the Null Device does not do anything with the value it doesn't really matter that it doesn't have the complete data. HB is able to update the Property Value with all of the data.



I was able to send 2000 items about 15 bytes long (30K of data)! with no trouble.



Scott

Posted: Sat Oct 18, 2003 3:50 pm
by kbosscawen
That's great news - Thanks for the quick response. 30K should do me - I only need 4-5K. When do you expect to post the next version?

Posted: Sat Oct 18, 2003 4:30 pm
by ScottBot
kbosscawen wrote:When do you expect to post the next version?
I'm hoping in about two weeks. I've finished all of the major work, I just need to test it for a while, work out any kinks, and update the docs.



Scott

Posted: Thu Oct 30, 2003 10:00 am
by ScottBot
Version 1.60 was just posted to the web site. It has the fix for the problem you are seeing.



Good Luck,

Scott